开发者

ICSharpCode zipfile creation error

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();
      开发者_Python百科  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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜