5

I try to download a zip file made by Ionic.Zip.dll from an asp.net c# web form application like this:

zip.AddEntry("filename", arraybyte);
Response.Clear();
Response.BufferOutput = false;
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "filename=SuppliersDocuments.zip");
zip.Save(Response.OutputStream);
Response.Close();

But I get Failed - network error like this:

enter image description here

Error just occurs in chrome and it works properly in another browsers. Error does not occur on my localhost and it happens only on the main server.

It would be very helpful if someone could explain solution for this problem.

Adhip Rebello
  • 135
  • 2
  • 12
Reza Amini
  • 476
  • 1
  • 5
  • 20

1 Answers1

1

I have the same issue and this happens in Chrome. This issue is happening on Chrome v53 and later which is explained here.

To overcome this issue I suggest you get the length of the file and use Content-Length in the header and pass the length of the file.

string fileName = string.Format("Download.zip");
Response.BufferOutput = false;  // for large files  
using (ZipFile zip = new ZipFile())
{
      zip.AddFile(path, "Download");
      Response.Clear();
      Response.Buffer = true;
      Response.ContentType = "application/zip";
      Response.AddHeader(name: "Content-Disposition", value: "attachment;filename=" + fileName);
      Int64 fileSizeInBytes = new FileInfo(path).Length;
      Response.AddHeader("Content-Length", fileSizeInBytes.ToString());                                    
      zip.Save(Response.OutputStream);
      Response.Flush();
}
Response.Close();
Adhip Rebello
  • 135
  • 2
  • 12
  • IDK while you were down voted. Yours is the correct answer. This one line where I totaled all the files sizes. Response.AddHeader("Content-Length", longAllFileSizes.ToString()); – Berry Wing Dec 03 '21 at 04:43