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”)
解决方法
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 举报,一经查实,本站将立刻删除。