I am using below code to zip the memory stream on the fly dynamically and creating excel file inside that zipfile .....using dotnetzip dll ......
public ActionResult ExportToExcel()
{
byte[] file;
DataTable dt = common.CreateExcelFile.ListToDataTable(GetSearchDraftPRResults());
common.CreateExcelFile excelFileForExport = new CreateExcelFile();
file = excelFileForExport.CreateExcelDocumentAsStream(dt, targetFilename);
Response.Buffer = true;
var memStream = new MemoryStream(file);
var memoryStream = new MemoryStream();
using (var zip = new ZipFile())
{
zip.AddEntry("Generate-Excel.xlsx","", memStream);
zip.Save(memoryStream);
}
memStream.Seek(0, SeekOrigin.Begin);
return File(memoryStream, "application/octet-stream", "archive.zip");
}
I am getting the file created as zip file but when I click on archive.Zip file I am getting error
ERROR
The Archive is either in unknown Format or Damaged
would any one please help on this why I am getting corrupted zip file when doing zip on fly that would be very grateful to me.