我设置了以下代码来创建一组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文件中被维护:
e.g
我正在创建一个所选文档的zip,这些文档位于
C:\SoftwareDevelopment\Branches\ScannedDocuments\
打开创建的zip文件时,zip中有一个文件夹结构,如下所示:
文件夹1 ("SoftwareDevelopment")
文件夹1内是文件夹2(“分支”)
文件夹2内是文件夹3 ("ScannedDocuments")
然后,扫描文档文件夹包含实际的扫描文件。
有人能告诉我,在不维护文件夹路径的情况下,如何才能将扫描文件放在zip中呢?
发布于 2013-03-08 10:14:53
文档声明第三个参数
directoryPathInArchive (String) 指定用于覆盖文件名中的任何路径的目录路径。此路径可能与当前文件系统中的实际目录相对应,也可能不对应。如果zip中的文件稍后被解压缩,这就是解压缩文件的路径。传递null (VB中没有任何内容)将在每个fileNames上使用路径(如果有的话)。传递空字符串("")将在存档中的根路径插入项。
因此,如果您总是希望将文件添加到zip存档的根目录中,请更改
loanZip.AddFiles(documentPaths, false, zipDestinationPath);至
loanZip.AddFiles(documentPaths, false, "");https://stackoverflow.com/questions/15291337
复制相似问题