Invalid zip file when I use Ionic.Zip library to zip

Jan 19 2017 12:36 PM
My application is using Ionic.Zip library to zip the file. Using DataTables and each DataTable would create an excel file and download them as a single excel file.

But when i download the file, through the windows, i cannot able to open the zip file and it shows invalid error. But with the help of WinZip, i can do it. Can anyone of you please advise why this strange thing occurs. My code below,
 
using (ZipFile zip = new ZipFile())
{
MemoryStream memoryStream = new MemoryStream();
foreach (KeyValuePair<string, DataTable> doc in attachmentColl)
{
using (ExcelPackage objExcelPackage = new ExcelPackage())
{
memoryStream = new MemoryStream();
ExcelWorksheet objWorksheet = objExcelPackage.Workbook.Worksheets.Add(doc.Key);
objWorksheet.Cells["A1"].LoadFromDataTable(doc.Value, true);
zip.AddEntry(doc.Key + ".xlsx", objExcelPackage.GetAsByteArray());
}
}
Response.Clear();
Response.BufferOutput = false;
string zipName = String.Format("Reports.zip");
Response.AppendHeader("content-disposition", "attachment; filename=" + zipName);
Response.ContentType = "application/x-zip-compressed";
zip.Save(Response.OutputStream);
HttpContext.Current.ApplicationInstance.CompleteRequest();
} 
 
Thanks in advance. 

Answers (1)