Get a copy of SharpZipLib.
Do something like the following:
* Create a ZipOutputStream:
* Write the output stream directly to the response stream
* Create an 'entry' for your excel file, with whatever filename you want.
* Stream the grid to the zip stream via the StreamWriter/HtmlTextWriter
* Finish and close the zip stream.
* End the response.
Code:
ZipOutputStream outputStream = new ZipOutputStream(Response.OutputStream);
ZipEntry entry = new ZipEntry("Worksheet.xls");
entry.DateTime = DateTime.Now;
outputStream.PutEntry(entry);
using(StreamWriter sw = new StreamWriter(outputStream))
{
// ... etc - the rest of your code, except the following two lines:
// HttpContext.Current.Response.Write(sw.ToString());
// HttpContext.Current.Response.End();
}
// Close the zip file:
outputStream.Finish();
outputStream.Close();
// Now end the response.
HttpContext.Current.Response.End();
/- Sam Judson : Wrox Technical Editor -/