我设置了以下代码来创建一组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\
文件夹1(“SoftwareDevelopment”)
解决方法
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,"");