ICSharpCode zip 文件创建错误

发布于 2024-09-03 21:11:34 字数 548 浏览 2 评论 0原文

以下代码在我的机器上有效,但在服务器上无效:

using (ZipFile zipFile = ZipFile.Create(outPath))
{       
    if (!includeFolders)
    {
        zipFile.NameTransform = 
            new ZipNameTransform(Path.GetDirectoryName(fileNames[0]));
    }

    foreach (string Fil in fileNames)
    {
        zipFile.BeginUpdate();
        zipFile.Add(Fil.ToLower());
        zipFile.CommitUpdate();
    }
}

它创建一个空的 zip 文件并引发此异常:

无法访问已处置的对象。 对象名称:“ZipFile”。

还有其他人遇到过这个错误吗?是否有替代方法或库来压缩没有文件夹的文件?

The following code works on my machine but not in server:

using (ZipFile zipFile = ZipFile.Create(outPath))
{       
    if (!includeFolders)
    {
        zipFile.NameTransform = 
            new ZipNameTransform(Path.GetDirectoryName(fileNames[0]));
    }

    foreach (string Fil in fileNames)
    {
        zipFile.BeginUpdate();
        zipFile.Add(Fil.ToLower());
        zipFile.CommitUpdate();
    }
}

It creates an empty zip file and throws this exception:

Cannot access a disposed object.
Object name: 'ZipFile'.

anyone else encountered this error? is there an alternative way or library to zip files without folders?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

青春如此纠结 2024-09-10 21:11:34

遇到了同样的问题,结果发生了,因为我尝试添加的一些文件不存在,并且在执行 zipFile.Add(file); 之后正在处理不存在的文件 zipFile 对象。 tl;dr:检查所有文件是否存在。

Had the same problem, turned out it happened because some of my files I tried to add didn't exist and after executing zipFile.Add(file); with non-existing file zipFile object is being disposed. tl;dr: Check that all your files DO exist.

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