微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 使用ion.zip创建zip文件

我设置了以下代码来创建一组doucments的zip文件
public bool CreateDocumentationZipFile(int documentIdentifier,string zipDestinationPath,IList<string> documentPaths)        
    {
        bool zipped = false;

        if (documentPaths.Count > 0)
        {
            using (ZipFile loanZip = new ZipFile())
            {
                loanZip.AddFiles(documentPaths,false,zipDestinationPath);
                loanZip.Save(string.Format("{0}{1}.zip",zipDestinationPath,documentIdentifier.ToString()));
                zipped = true;
            }
        }

        return zipped;
    }

我的问题是,当zip文件被创建时,文件夹结构在zip文件中被维护:

例如

我正在创建一系列位于的文件

C:\SoftwareDevelopment\Branches\ScannedDocuments\

当创建的zip文件打开时,zip中有一个文件夹结构如下:

文件夹1(“SoftwareDevelopment”)

文件夹1是文件夹2(“分支”)

内部文件夹2是文件夹3(“扫描文档”)

扫描的文档文件夹包含实际的扫描文件.

任何人都可以告诉我如何在zip中没有保存文件夹路径的扫描文件

解决方法

documentation说第三个参数

directoryPathInArchive (String)
Specifies a directory path to use to override any path in the file
name. This path may,or may not,correspond to a real directory in the
current filesystem. If the files within the zip are later extracted,
this is the path used for the extracted file. Passing null (nothing in
VB) will use the path on each of the fileNames,if any. Passing the
empty string (“”) will insert the item at the root path within the
archive.

所以如果你总是希望将这些文件添加到您的zip存档的根目录下,请改变

loanZip.AddFiles(documentPaths,zipDestinationPath);

loanZip.AddFiles(documentPaths,"");

原文地址:https://www.jb51.cc/csharp/95887.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐