This code is a useful way of creating a zip archive on the fly:
(I didn't think it would be helpful to post the entire code here)
http://www.codeproject.com/Articles/209731/Csharp-use-Zip-archives-without-external-libraries
I'm using it to zip text files for downloading via Response.BinaryWrite.
This is my implementation:
files
and fileNames
are each a List<string>
// add the files to a zip
var str = new MemoryStream();
using (var arc = ZipArchive.OpenOnStream(str))
{
for (int i = 0; i < files.Count(); i++)
{
using (var fs = arc.AddFile(fileNames[i]).GetStream(FileMode.Open, FileAccess.ReadWrite))
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
Byte[] bytes = encoding.GetBytes(files[i]);
fs.Write(bytes, 0, bytes.Length);
}
}
}
result = str.GetBuffer();
// return the zip
return result;
My question is, can anyone think of a way to store the files in separate folders in the archive?
Thanks for any help!