我正在创建Ionic.Zip.dll
这样的zip(ASP.NET,C#):
zip.AddEntry("Document.jpeg", File.ReadAllBytes("Path");
我想这样下载:
Response.Clear();
Response.BufferOutput = false;
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "filename=SuppliersDocuments.zip";
zip.Save(Response.OutputStream);
Response.Close();
我通过Firefox和Chrome在localhost中测试了这段代码,它运行正常。但是当我在主机中测试这段代码时,我收到了这个错误:
失败 - 网络错误
我的代码是错的吗?
答案 0 :(得分:0)
我在转发SSRS报告时遇到了类似的问题。根据@Arvin的建议,我做了以下事情:
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)
}
修复程序是添加Content-Length标头并将其设置为来自报告服务的字节数组的大小。