加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 06:19:04 所属栏目:百科 来源:网络整理
导读:我设置了以下代码来创建一组doucments的zip文件: public bool CreateDocumentationZipFile(int documentIdentifier,string zipDestinationPath,IListstring documentPaths) { bool zipped = false; if (documentPaths.Count 0) { using (ZipFile loanZip =
我设置了以下代码来创建一组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:SoftwareDevelopmentBranchesScannedDocuments

当创建的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,"");

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读