Failed - network error when downloading excel file made by EPPlus.dll

前端 未结 5 2297

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 erro

相关标签:
5条回答
  • 2021-02-19 23:55

    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();
    
    0 讨论(0)
  • 2021-02-20 00:07

    I had the same problem and I solved with the code below, note the quotes in filename=\"Name.xlsx\":

    Response.Buffer = true;
    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    Response.AppendHeader("content-disposition", "attachment; filename=\"Name.xlsx\"");
    //Writeout the Content  
    Response.BinaryWrite(bytes);
    
    0 讨论(0)
  • 2021-02-20 00:08

    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; 
        }
    
    0 讨论(0)
  • 2021-02-20 00:11

    I am exporting html table code which is in string variable HTML

    Following Code Working For Me

    byte[] myFile = Encoding.ASCII.GetBytes(HTML);
            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("Content-Type", "application/excel");
            Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0};", "BAGrowthReport.xls"));
            Response.AddHeader("content-length", myFile.Length.ToString()); //Here is the additional header which is required for Chrome.
            Response.BinaryWrite(myFile);
            Response.Flush();
            Response.Close();
    
    0 讨论(0)
  • 2021-02-20 00:18

    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();
    }   
    
    0 讨论(0)
提交回复
热议问题