My problem seems only to be with the download. The code above executes without any issue. A file download dialog is presented. I can choose to either save or open. If I try to open the file from the dialog, or save it and then open it. I get the following dialog message:
The Compressed (zipped) Folder is invalid or corrupted.
my code
- List<string> folderpath = new List<string>();
- var zip = new ZipFile();
- gridview.AllowPaging = false;
- Response.ClearContent();
- string zipName = String.Format("Zip_{0}.zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"));
- Response.AddHeader("content-disposition", "attachment; filename=" + zipName);
- Response.ContentType = "application/zip";
- System.IO.StringWriter sw = new System.IO.StringWriter();
- HtmlTextWriter htw = new HtmlTextWriter(sw);
- gridview.RenderControl(htw);
-
- MemoryStream stream = new MemoryStream();
- string attachment = sw.ToString();
- byte[] data = Encoding.ASCII.GetBytes(attachment);
- stream.Write(data, 0, data.Length);
- stream.Seek(0, SeekOrigin.Begin);