SharpZipLib 仅压缩目录的某些子目录

发布于 2024-08-05 03:59:05 字数 311 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

囍孤女 2024-08-12 03:59:05

几种可能:

权限 - 由于您使用的是 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.

白色秋天 2024-08-12 03:59:05

经过一番调试,我发现了问题。
问题的原因是,在向创建的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文