Click here to Skip to main content
15,889,777 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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,

What I have tried:

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();
}
Posted
Updated 19-Jan-17 3:51am
v2

1 solution

If you can read it with WinZip but not open it in Windows directly, then it's possible that the ZIP file produced is a later version than your variant of Windows supports: not all ZIP files are the same format, and some systems have problems with higher compressions.
Try changing the SetCompression Property[^] value to a lower value and see if that helps.
 
Share this answer
 
Comments
DPM20 19-Jan-17 8:25am    
Thank you for the quick revert.

Tried with setting compression level, but no luck!!
zip.CompressionLevel = Ionic.Zlib.CompressionLevel.Level0;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900