0

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Glory Raj
  • 17,397
  • 27
  • 100
  • 203

1 Answers1

0

I have rectified my problem with this line memoryStream.Seek(0, SeekOrigin.Begin); replacing this one memStream.Seek(0, SeekOrigin.Begin);

Glory Raj
  • 17,397
  • 27
  • 100
  • 203