【发布时间】:2017-09-21 16:08:28
【问题描述】:
我有这个下载功能:
protected void ExportData(string fileName, string fileType, string path)
{
System.IO.StreamReader sr = new System.IO.StreamReader(path);
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
Response.Charset = "";
Response.ContentType = fileType;
Response.Output.Write(sr.ReadToEnd());
Response.Flush();
Response.End();
}
我用它:
ExportData("infoMandat_" + g.NO_MANDAT + ".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", g.URL_infoMandat);
但文件始终为空或已损坏...
可能是因为我用普通的StreamReader阅读它
答案中提出的解决方案是函数.Transmit(),标记为重复的问题绝对不是这个问题的解决方案。
【问题讨论】:
-
path的值是多少?它是和这段代码在同一台机器上还是在其他地方? -
读取 DOCX 文件时是否出现异常错误?如果是,异常错误的消息文本是什么?
-
URL_infoMandat的值是多少? -
@Equalsk 路径将指向另一台服务器,但现在,在我的 c:\