Failed - network error when downloading excel file made by EPPlus.dll
12,603
Solution 1
Try this:
using (ExcelPackage p = new ExcelPackage())
{
//Code to fill Excel file with data.
Byte[] bin = p.GetAsByteArray();
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", Nombre_Del_Libro + ".xlsx"));
Response.BinaryWrite(bin);
Response.Flush();
Response.End();
}
Solution 2
I had the same problem when I was using Response.Clear() and Response.Close() and had to avoid them to look my code as below which is working.
Response.Buffer = true;
Response.ContentType = mimeType;
Response.AddHeader("Content-Disposition", "attachment; filename=" + nameOfFile);
Response.BinaryWrite(bytes);
Response.End();
Solution 3
I prefer not use response.End() because throw an exception
protected void DownloadFile(FileInfo downloadFile, string downloadFilename, string downloadContentType)
{
Byte[] bin = File.ReadAllBytes(downloadFile.FullName);
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = downloadContentType;
Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", downloadFilename ));
Response.BinaryWrite(bin);
Response.Flush();
Response.SuppressContent = true;
}
Author by
Reza Amini
Updated on June 14, 2022Comments
-
Reza Amini almost 2 years
I try to download an excel file made by
EPPlus.dll
from an asp.net c# web form application. but i get Failed - network error. It should be noted that mentioned error just occurs in chrome and the job can be done successfully in another browsers.by the way this error does not occure on my localhost and it happens only on the main server.
It would be very helpful if someone could explain solution for this problem.
-
Zaveed Abbasi almost 6 yearsWhen i set extension to ".xlsx" , its not getting opened in Excel(2016) on development environment. When i change it to ".xlx", it working. What could be the reason?
-
Jake Gaston over 4 yearsStrange it had been working on my site with clear and close, then suddenly I started getting this error. Using End seems to have fixed it, thanks.