繁体   English   中英

使用 Response.TransmitFile 时出现网络故障

[英]Network Failure when using Response.TransmitFile

我正在尝试使用以下代码,以允许用户下载位于本地服务器上的 excel:

FileInfo dest_file= new FileInfo(filename);
Response.ClearContent();
Response.ContentType = "Excel/xls";
Response.AddHeader("Content-Disposition", string.Format("attachment; filename = {0}", filename));
Response.AddHeader("Content-Length", dest_file.Length.toString());
Response.TransmitFile(filename);
Response.End();

但是,在发布解决方案后,下载文件会导致网络故障。 知道如何解决这个问题吗?

请注意,当尝试通过目录浏览访问文件时,文件下载成功。

您似乎使用了无效的内容类型

对于xlsx使用这个

Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

对于xls

Response.ContentType = "application/vnd.ms-excel"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM