SharpZipLib 仅压缩目录的某些子目录
我正在使用 SharpZipLib 在 .NET 3.5 项目中创建目录的 zip 文件,并且我正在创建这样的存档:
fastZip.CreateZip(Server.MapPath(zipToPath), Server.MapPath(zipFromPath), true, null);
而且这既不设置文件也不设置文件夹过滤器。
问题是,结果 zip 文件只有该目录中的部分子目录,而不是全部,假设我要压缩的目录有 3 个子目录,生成的 zip 文件只有其中一个。
有什么想法为什么会发生这种情况吗?
I'm using SharpZipLib to create a zip file of a directory in a .NET 3.5 project, and I'm creating the archive like that :
fastZip.CreateZip(Server.MapPath(zipToPath), Server.MapPath(zipFromPath), true, null);
And that doesn't set neither files nor folders filters.
The problem is that the outcome zip file only has some of the sub-directories in that directory and not all of them, say the directory I want to compress has 3 sub-directories, the resulting zip file has only one of them.
Any ideas why is this happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
几种可能:
权限 - 由于您使用的是 Server.MapPath(),我假设这是一个网站。在部分信任的环境中,网站代码的权限非常少,并且库可能会吞掉 zip 过程中发生的任何权限错误。
文件名 - 可能是文件名长度、文件名中的空格等问题。由于您没有提供任何示例(文件/目录名称),因此无法缩小范围。
A couple of possibles:
Permissions - Since you're using Server.MapPath(), I'm assuming this is a website. In a partial-trust environment the website code has very few permissions, and the library may be swallowing any permissions errors that are occurring during the zip process.
Filenames - Could be a problem with filename length, spaces in the filenames, etc, etc. Since you haven't provided any examples (of the file/directory names, there's no way to narrow it down.
经过一番调试,我发现了问题。
问题的原因是,在向创建的 zip 文件添加文件期间,另一个进程正在访问该文件,这会导致 SharpZipLib 进程终止并引发异常,从而使创建的 zip 文件仅包含部分文件。
有关更多信息,请阅读我的如何知道哪些进程正在使用 ASP.NET 下的文件? 问题。
After some debugging I've found the problem.
The cause of the issue is that another process is accessing the created zip file during adding files to it, which causes the SharpZipLib process to terminate and throw an exception, leaving the created zip file with only some of the files.
For more please read my How to know which processes is using a file under ASP.NET? question.