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

前端 未结 5 2418

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-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; 
        }
    

提交回复
热议问题