The following code uses our Rebex ZIP and shows how to add files to a ZIP archive without using a temporary file. Then the ZIP is sent to the web browser.
using (MemoryStream ms = new MemoryStream())
{
using (ZipArchive zip = new ZipArchive(ms))
{
zip.Add(@"c:\temp\testfile.txt");
zip.Add(@"c:\temp\innerfile.txt", @"\subfolder");
Response.Clear();
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "filename=sample.zip");
ms.WriteTo(Response.OutputStream);
}
}
HttpContext.Current.ApplicationInstance.CompleteRequest();
See the ZIP tutorial for more information .
Alternative solution:
SharpZipLib and DotNetZip made extensive use of free alternatives.
source
share