In DotNetZip, adding files to an existing zip is really simple and reliable.
using (var zip = ZipFile.Read(nameOfExistingZip))
{
zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
zip.AddFile(additionalFileToAdd);
zip.Save();
}
If you want to specify a directory path for that new file, then use a different overload for AddFile().
using (var zip = ZipFile.Read(nameOfExistingZip))
{
zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
zip.AddFile(additionalFileToAdd, "directory\For\The\Added\File");
zip.Save();
}
If you want to add a set of files, use AddFiles().
using (var zip = ZipFile.Read(nameOfExistingZip))
{
zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
zip.AddFiles(listOfFilesToAdd, "directory\For\The\Added\Files");
zip.Save();
}
You don't have to worry about Close(), CloseEntry(), CommitUpdate(), Finish() or any of that other gunk.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…