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 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();
}
{
MemoryStream memoryStream = new MemoryStream();
foreach (KeyValuePair
{
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.
Nigel FernandesPosted Jan 19, 2017, 8:23 PM