I wanted to present a code that generates a zip file in memory and then send it by Customer Request.
code is a fairly simple but can get us out of trouble.
Use the library, which can be downloaded from: http://dotnetzip.codeplex.com/
private void
I hope will be useful. Greetings
responseZipFile (Object data, object sender, EventArgs e)
{using (StringWriter sw = new StringWriter ()) {
using (MemoryStream ms = new MemoryStream ()) {
Response.Clear ();
Response.Buffer = true;
Response.ContentType = "aplication/zip";
Response.AddHeader("Content-Disposition", "attachment;filename=file.zip");
this.EnableViewState = false;
using (ZipFile zip = new ZipFile())
{
zip.AddEntry("Readme.txt", "stringContent1");
zip.AddEntry("readings/Data.csv", "stringContent2");
zip.AddEntry("readings/Index.xml", "stringContent3");
zip.Save(ms);
}
HttpContext.Current.Response.BinaryWrite(ms.ToArray());
HttpContext.Current.Response.End();
}
}}
0 comments:
Post a Comment