有没有办法打开和读取 PXUploadDialog 以编程方式上传的 zip 文件? [英] Is there a way to open and read zip files programmatically uploaded by PXUploadDialog?

查看:25
本文介绍了有没有办法打开和读取 PXUploadDialog 以编程方式上传的 zip 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户想要上传一个 zip 文件,其中包含多个图像和一个包含与图像相关的数据的 CSV 文件.他们希望能够上传 zip 文件,并让程序通过查找和处理 CSV 文件中的数据来解析它,然后将 zip 中的图像存储到适当的位置.

I have a user that wants to upload a zip file that contains multiple images and a single CSV file with data related to the images. They want to be able to upload the zip file and have the program dissect it by finding and processing the data within the CSV file and then storing the images within the zip to their appropriate locations.

我正在尝试弄清楚如何打开 zip,以便我可以循环浏览其中的每个文件以找到我需要的内容.有没有办法做到这一点?

I'm trying to figure out how to open the zip so I can cycle through each file in there to find what I need. Is there any way to do this?

推荐答案

您可以使用 Acumatica Framework 中的 ZipArchive:

You can use ZipArchive from Acumatica Framework:

// Uploaded file needs to be attached to a DAC record
Guid[] files = PXNoteAttribute.GetFileNotes(DACCache, DACRecord);
UploadFileMaintenance upload = PXGraph.CreateInstance<UploadFileMaintenance>();

foreach (Guid fileID in files)
{
    FileInfo fileInfo = upload.GetFile(fileID);

    if (fileInfo != null)
    {
        using (MemoryStream stream = new MemoryStream(fileInfo.BinData))
        {
            ZipArchive zip = ZipArchive.OpenReadonly(stream);

            string tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            Directory.CreateDirectory(tempDirectory);
            ZipFolder.Decompress(zip, tempDirectory, true);

            foreach (string filePath in Directory.GetFiles(tempDirectory))
            {
                // Enumerating decompressed files
            }
        }
    }
}

这篇关于有没有办法打开和读取 PXUploadDialog 以编程方式上传的 zip 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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