sharpziplib + Whenever i try to add a file to existing archive, it overwrites previous contents
- by schmoopy
I am trying to add files to an existing zip file. Whenever i do, the new one contains the new list of files im passing in, but all of the previous ones are wiped out.
I have also tried the code here: http://stackoverflow.com/questions/1356003/c-sharpziplib-adding-file-to-existing-archive -- same results
Any idea why i cannot add files to an existing zip while maintaining the previous files?
Here is the code:
public static void AddFileToZip(string currentZipPath, List<string> files, bool includeFullPathInEntry, int compressionLevel)
{
ZipOutputStream zipStrm = new ZipOutputStream(File.Open(currentZipPath, FileMode.Open, FileAccess.ReadWrite));
zipStrm.SetLevel(compressionLevel);
foreach (string str in files)
{
string entryName = str;
if (!includeFullPathInEntry)
entryName = new FileInfo(str).Name;
ZipEntry entry = new ZipEntry(entryName);
zipStrm.PutNextEntry(entry);
Byte[] b = File.ReadAllBytes(str);
zipStrm.Write(b, 0, b.Length);
}
zipStrm.Finish();
zipStrm.Close();
}