Reputation: 476
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:
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.
Upvotes: 5
Views: 2476
Reputation: 145
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();
Upvotes: 1