2017-02-19 4 views
3

Ich bin eine Zip von Ionic.Zip.dll wie folgt aus (ASP.NET, C#) zu erstellen:fehlgeschlagen - Netzwerkfehler in get Zip-Datei in Chrom

zip.AddEntry("Document.jpeg", File.ReadAllBytes("Path"); 

Ich möchte es so zum Download:

Response.Clear(); 
Response.BufferOutput = false; 
Response.ContentType = "application/zip"; 
Response.AddHeader("content-disposition", "filename=SuppliersDocuments.zip"; 
zip.Save(Response.OutputStream); 
Response.Close(); 

Ich habe diesen Code in localhost von Firefox und Chrome getestet und es hat richtig funktioniert. Aber wenn ich diesen Code im Host teste, erhalte ich diesen Fehler:

Failed - network error

Ist mein Code falsch?

+1

versuchen, content-Size zum Response-Header hinzuzufügen. Lass mich wissen ob es funktioniert. – Kahbazi

Antwort

0

Ich stieß auf ein ähnliches Problem mit der Weitergabe eines SSRS-Berichts. Unter @ Arvin Vorschlag, habe ich folgendes:

private void CreateReport(string ReportFormat) 
{ 
    ReportViewer rview = new ReportViewer(); 

    // (setup report viewer object) 

    // Run report 
    byte[] bytes = rview.ServerReport.Render(ReportFormat, deviceInfo, out mimeType, out encoding, out extension, out streamids, out warnings); 

    // Manually create a response 
    Response.Clear(); 
    Response.ContentType = mimeType; 
    Response.AddHeader("Content-disposition", string.Format("attachment; filename={0}.{1}", fileName, extension)); 

    // Ensure the content size is set correctly 
    Response.AddHeader("Content-Length", bytes.Length.ToString()); // <- important 

    // Write to the response body 
    Response.OutputStream.Write(bytes, 0, bytes.Length); 

    // (cleanup streams) 
} 

Das Update des Content-Length-Header wurde hinzugefügt und es auf die Größe des Byte-Arrays Einstellung von Reporting Services.

Verwandte Themen