Create Zip file from stream and download it

Posted by Navid Farhadi on Stack Overflow See other posts from Stack Overflow or by Navid Farhadi
Published on 2010-02-15T13:29:07Z Indexed on 2010/03/31 16:33 UTC
Read the original article Hit count: 438

Filed under:
|
|
|
|

I have a DataTable that i want to convert it to xml and then zip it, using DotNetZip. finally user can download it via Asp.Net webpage. My code in below

    dt.TableName = "Declaration";

    MemoryStream stream = new MemoryStream();
    dt.WriteXml(stream);

    ZipFile zipFile = new ZipFile();
    zipFile.AddEntry("Report.xml", "", stream);
    Response.ClearContent();
    Response.ClearHeaders();
    Response.AppendHeader("content-disposition", "attachment; filename=Report.zip");

    zipFile.Save(Response.OutputStream);
    //Response.Write(zipstream);
    zipFile.Dispose();

the xml file in zip file is empty.

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET