Proxy > Gmail Facebook Yahoo!

ASP.NET – Download as ZIP




DotNetZipLib is one of the best compression/zip libraries for dotnet I found. You can download it from CodePlex.
Here is a snippet which demonstrates how to use DotNetZipLib to zip and force download directly to browser.
ZipFile zip = new ZipFile();
 
// Add files to zip
zip.AddFile(@"C:\blah.jpg", string.Empty);
zip.AddFile(@"C:\blee.jpg", string.Empty);
 
// save to memory stream instead of a direct file
MemoryStream ms = new MemoryStream();
zip.Save(ms);
 
//convert to bytes
byte[] bytes = ms.ToArray();
ms.Flush();
ms.Close();
 
// Download now
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=myzipfile.zip");
Response.AddHeader("Content-Length", bytes.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(bytes);


Responses

0 Respones to "ASP.NET – Download as ZIP"


Send mail to your Friends.  

Expert Feed

 
Return to top of page Copyright © 2011 | My Code Logic Designed by Suneel Kumar