2016-09-21 12 views
9

EPPlus.dllで作成したExcelファイルをasp.net c#webフォームアプリケーションからダウンロードしようとしています。しかし、私は失敗しました - ネットワークエラー。 上記のエラーはクロムでのみ発生し、別のブラウザで正常に処理できることに注意してください。EPPlus.dll製Excelファイルのダウンロードに失敗しました

ところで、このエラーはローカルホストでは発生せず、メインサーバーでのみ発生します。

誰かがこの問題の解決方法を説明できると非常に役に立ちます。

http://www.irandnn.ir/blog/PostId/29/epplus

+0

po実際にこのファイルがクライアントに送信されているclickイベントなどのコード。 – Rex

答えて

5

このお試しください:私は同じ問題を抱えていたし、私は以下のコードで解決し、ファイル名に引用符を注意= \ "Name.xlsx \"

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(); 
} 
12

私はResponse.Clear()を使用してResponse.Close()されたときに同じ問題を抱えていたし、それより下が働いているように私のコードを見て、それらを避けるために持っていました。

Response.Buffer = true; 
Response.ContentType = mimeType; 
Response.AddHeader("Content-Disposition", "attachment; filename=" + nameOfFile); 
Response.BinaryWrite(bytes); 
Response.End(); 
0

を:

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); 
1

私は例外をスローするためにresponse.End()を使いません。

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

これは私の問題を解決しました。ありがとうございました – Sergio

関連する問題