downloading excel from server showing me failed network error in chrome browser and in firefox Pr8zzTpI.xlsx.part could not be saved.

Sunil Shinde 1 Reputation point
2022-09-29T12:18:47.927+00:00

downloading excel from server showing me failed network error in chrome browser and in firefox showing error as below
C:\Users\Sunil\Downloads\Pr8zzTpI.xlsx.part could not be saved, because the source file could not be read.

I am using epplus lib for generating excel , i see excel has been generated in a folder but not able to download it.
here is my code.
private void DOWNLOAD_FILE()
{
try
{
if (!string.IsNullOrEmpty(Request.QueryString["reportPath"]) && !string.IsNullOrEmpty(Request.QueryString["FileName"]))
{
string reportPath = Request.QueryString["reportPath"];
string FileName = Request.QueryString["FileName"];
logerrors.logerror("reportPath " + reportPath);
logerrors.logerror("FileName " + FileName);
Response.ClearContent();
Response.Buffer = true;
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", FileName));
Response.TransmitFile(reportPath);
//Response.End();
Response.Flush();
Response.Close();
}
else
{
logerrors.logerror("Invalid Report Path Or ReportName");
}
}
catch (Exception ex)
{
logerrors.logerror(ex.Message);
}
}

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,263 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sunil Shinde 1 Reputation point
    2022-10-08T04:09:57.573+00:00

    At server tried this
    Response.TransmitFile(reportPath);
    Response.End();
    //Response.Flush();
    //Response.Close();

    Now it isworking fine.

    0 comments No comments