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,"");

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...