asp.net导出Word:点击导出按钮页面变成空白,也无Word生成
一个根据文档模板格式填充数据后在生成Word文档下载
public Boolean ExportCustomsDocumentObject(Page page, string filename, out string errormsg)
{
Boolean writeOk = true;
byte[] allbytes = null;
try
{
string fileName =
HttpContext.Current.Server.MapPath("~/App_Code/WebApiService/xxxTemplate.docx");
allbytes = OutCountrySituationDocumentEngine.GetOutCountrySituationDocumentObjectBytes(fileName,
int.Parse(cmdYear.SelectedValue), int.Parse(cmdQuarter.SelectedValue));
Response.ClearHeaders();
Response.ClearContent();
Response.AppendHeader("content-disposition",
"attachment; filename=" + HttpUtility.UrlEncode(filename, Encoding.UTF8));
Response.ContentType = "application/ms-word";
Response.BinaryWrite(allbytes);
Response.End();
}
catch (Exception e)
{
}
errormsg = "";
return writeOk;
}
问题描述:
在vs中可以正常的运行且生成了Excel文件并可以下载。
部署到iis后,点击输出按钮,页面变成空白(其他页面都正常)。