如何通过HTTP虚拟路径将文件上传到Acumatica屏幕? [英] How do I upload a file to an Acumatica Screen through HTTP virtual path?

查看:86
本文介绍了如何通过HTTP虚拟路径将文件上传到Acumatica屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过HTTP虚拟路径将文件上传到Acumatica屏幕?
例如,我想将mysite.com/files/abc.pdf上传到销售订单屏幕。

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.

推荐答案

下面是实现您的目标的代码段。它是从HTTP URL读取文件并将其附加到现有Case之一。

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

这篇关于如何通过HTTP虚拟路径将文件上传到Acumatica屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆