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.
精彩评论