I have a class which is sort of like a repository, and every time I write to the zip archive using this command, the prior activity is overwritten.
/// <summary>
/// Insert file into existing archive file.
/// </summary>
/// <param name="fullPath"></param>
/// <param name="stream"></param>
public void InsertIntoFile(String fullPath, Stream stream) {
using (var fs = new FileStream(FullArchivalPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)) {
using (var zipOutput = new ZipOutputStream(fs)) {
zipOutput.SetLevel(9);
if (fullPath.Contains(@"\")) {
ZipEntry zipDir = new ZipEntry(Path.GetDirectoryName(fullPath) + @"\");
zipDir.DateTime = DateTime.Now;
zipOutput.PutNextEntry(zipDir);
}
ZipEntry zipEntry = new ZipEntry(fullPath);
zipEntry.DateTime = DateTime.Now;
zipOutput.PutNextEntry(zipEntry);
var length = (int)stream.Length;
byte[] content = new byte[length];
stream.Read(content, 0, length);
zipOutput.Write(content, 0, length);
zipOutput.CloseEntry();
zipOutput.Finish();
zipOutput.Close();
}
}
}//end method