How do I upload a file to an Acumatica Screen through HTTP virtual path?

末鹿安然 提交于 2019-12-08 04:24:32

问题


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.


回答1:


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();
                  }
              }
          }
      }


来源:https://stackoverflow.com/questions/25357224/how-do-i-upload-a-file-to-an-acumatica-screen-through-http-virtual-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!