zip在4.2到6.0中的工作方式不同

时间:2017-01-24 19:00:53

标签: c# acumatica

我在版本4.2中进行了自定义并且正常工作,现在我正在使用版本6,但是自定义不能以相同的方式工作。 我想压缩一个包含文件的文件夹。 你能帮我解决这个问题吗?做同样的新方法是什么? :(

这是我的代码:

using (MemoryStream stream = new MemoryStream())
        {
            using (PX.Data.Update.ZipArchive zip = new PX.Data.Update.ZipArchive(stream, false))
            {
                zip.AddFolder(direc);
            }
            string path = "ArchivosXML.zip";
            PX.SM.FileInfo info = new PX.SM.FileInfo(path, null, stream.ToArray());
            throw new PXRedirectToFileException(info, true);
        }

1 个答案:

答案 0 :(得分:2)

看起来 ZipArchive 类已从PX.Data.Update命名空间移至PX.Common

以下是2个样本,完美适用于6.0,展示了如何:

  • 将当前销售订单中的所有附件同步导出到Zip存档中:

    public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
    {
        public PXAction<SOOrder> ExportAttachmnts;
        [PXButton]
        [PXUIField(DisplayName = "Export Attachments")]
        protected void exportAttachmnts()
        {
            var order = Base.Document.Current;
    
            using (MemoryStream stream = new MemoryStream())
            {
                using (PX.Common.ZipArchive archive = PX.Common.ZipArchive.CreateFrom(stream, false))
                {
                    UploadFileMaintenance upload = PXGraph.CreateInstance<UploadFileMaintenance>();
    
                    Guid[] uids = PXNoteAttribute.GetFileNotes(Base.Document.Cache, order);
                    foreach (Guid uid in uids)
                    {
                        PX.SM.FileInfo fileInfo = upload.GetFile(uid);
                        archive.AddFile(fileInfo.Name, fileInfo.BinData);
                    }
                }
                PX.SM.FileInfo info = new PX.SM.FileInfo(
                    string.Format("{0}-{1}-Attachmets.zip", order.OrderType, order.OrderNbr),
                    null, stream.ToArray());
                throw new PXRedirectToFileException(info, true);
            }
        }
    }
    
  • 从Zip存档中异步导出当前销售订单的所有附件:

    public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
    {
        public PXAction<SOOrder> ExportAttachmnts;
        [PXButton]
        [PXUIField(DisplayName = "Export Attachments")]
        protected void exportAttachmnts()
        {
            var order = Base.Document.Current;
    
            PXLongOperation.StartOperation(Base, () =>
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    using (PX.Common.ZipArchive archive = PX.Common.ZipArchive.CreateFrom(stream, false))
                    {
                        UploadFileMaintenance upload = PXGraph.CreateInstance<UploadFileMaintenance>();
    
                        Guid[] uids = PXNoteAttribute.GetFileNotes(Base.Document.Cache, order);
                        foreach (Guid uid in uids)
                        {
                            PX.SM.FileInfo fileInfo = upload.GetFile(uid);
                            archive.AddFile(fileInfo.Name, fileInfo.BinData);
                        }
                    }
                    PX.SM.FileInfo info = new PX.SM.FileInfo(
                        string.Format("{0}-{1}-Attachmets.zip", order.OrderType, order.OrderNbr),
                        null, stream.ToArray());
                    throw new PXRedirectToFileException(info, true);
                }
            });
        }
    }