• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 389
  • Last Modified:

export grid view to excel then compress to zip

hello all of you ,
i am trying to export grid view to excel then compress it to zip
here is the code of exporting to excel
any help to compress it to zip ?????
public void ExportGridViewToExcel(HttpResponse Response, GridView GridView_Excel)

        string attachment = "attachment; filename=Transactions.xls";


        Response.AddHeader("content-disposition", attachment);
        // Response.ContentEncoding = System.Text.Encoding.UTF7;
        Response.Charset = "";
        Response.ContentType = "application/ms-excel";

        StringWriter sw = new StringWriter();

        HtmlTextWriter htw = new HtmlTextWriter(sw);





Open in new window

1 Solution
Instead of writing the stream writer to the response stream, you will have to write it to a file on the server and then use somehting like GZip to compress it and send the zip file to the response stream - http://www.dotnetspark.com/kb/1892-compress-and-decompress-data-using-gzipstream.aspx.

I'm not sure, but you may be able to use GZip directly on the sw object and compress the stream in memory instead of writing to the disk. The example also shows displaying the data to a textbox, but you can take and send the GZip stream to the response.
AhmedHindyAuthor Commented:
This will help in windows applications
i want to use it in Asp.net
any help

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now