graphically it can be done this way

but I need to bring the pdf file from a local path and then upload it through code
graphically it can be done this way

but I need to bring the pdf file from a local path and then upload it through code
Best answer by VardanV
Change your code by the following example:
public class SOShipmentEntryExt : PXGraphExtension<SOShipmentEntry>
{
public static bool IsActive() => true;
public PXAction<SOShipment> ApiTracking;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Tracking")]
public IEnumerable apiTracking(PXAdapter adapter)
{
string filePath = @"C:\Path\To\DownloadedFiles\downloadedFile4.pdf";
if (File.Exists(filePath))// Check if the file exists at the specified path
{
List<SOShipment> shipmentList = adapter.Get<SOShipment>().ToList();
PXLongOperation.StartOperation(this.Base.UID, delegate ()
{
SOShipmentEntry shipmentEntry = PXGraph.CreateInstance<SOShipmentEntry>();
UploadFileMaintenance upl = PXGraph.CreateInstance<UploadFileMaintenance>();
foreach (SOShipment shipment in shipmentList)
{
shipmentEntry.Clear();
shipmentEntry.Document.Current = shipmentEntry.Document.Search<SOShipment.shipmentNbr>(shipment.ShipmentNbr);
// Create a FileInfo object for the PDF file
PX.SM.FileInfo fileinfo = new PX.SM.FileInfo($"{Path.GetFileNameWithoutExtension(filePath)}.pdf", null, File.ReadAllBytes(filePath));
if (upl.SaveFile(fileinfo, FileExistsAction.CreateVersion))
{
PXNoteAttribute.SetFileNotes(shipmentEntry.Document.Cache, shipmentEntry.Document.Current, fileinfo.UID.Value);
shipmentEntry.Save.Press();
}
}
});
}
else
{
// Handle the case where the file is not found at the specified path
PXTrace.WriteWarning($"PDF file not found at path: {filePath}");
}
return adapter.Get();
}
}You need make sure that file path is accessible for read action.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.