1

How do I upload a file to an Acumatica Screen through HTTP virtual path? For example, I would like to upload mysite.com/files/abc.pdf to the Sales orders screen.

DChhapgar
  • 2,280
  • 12
  • 18
SharifA
  • 48
  • 6

1 Answers1

3

Below is a code snippet to achieve your goal.It is reading file from HTTP URL and attaching it to one of the existing Case.

      //Graph for file management
      PX.SM.UploadFileMaintenance filegraph = PXGraph.CreateInstance<PX.SM.UploadFileMaintenance>();
      //Since you need file from HTTP URL - below is a sample
      WebRequest request = WebRequest.Create("http://www.pdf995.com/samples/pdf.pdf");
      using (System.IO.Stream dataStream = request.GetResponse().GetResponseStream())
      {
          using (System.IO.MemoryStream mStream = new System.IO.MemoryStream())
          {
              dataStream.CopyTo(mStream);
              byte[] data = mStream.ToArray();                 

              //Create file info, you may check different overloads as per your need
              PX.SM.FileInfo fileinfo = new PX.SM.FileInfo("case.pdf", null, data);

              if (filegraph.SaveFile(fileinfo))
              {
                  if (fileinfo.UID.HasValue)
                  {
                      // To attach the file to case screen - example
                      CRCaseMaint graphCase = PXGraph.CreateInstance<CRCaseMaint>();

                      //Locate existing case
                      graphCase.Case.Current = graphCase.Case.Search<CRCase.caseCD>("<Case to which you want to attach file>");

                      //To Attach file
                      PXNoteAttribute.SetFileNotes(graphCase.Case.Cache, graphCase.Case.Current, fileinfo.UID.Value);

                      //To Attach note
                      PXNoteAttribute.SetNote(graphCase.Case.Cache, graphCase.Case.Current, "<Note you wish to specify>");

                      //Save case
                      graphCase.Save.Press();
                  }
              }
          }
      }
DChhapgar
  • 2,280
  • 12
  • 18
  • it appears that the PX.SM.FileInfo file name must be unique across all files. In this example "case.pdf" cannot already exist as a file name or the savefile will fail. (as of 17.200.0223) Otherwise i was able to get this example working for a different graph. Nice post DChhapgar – Brendan Sep 03 '17 at 15:16