我正在尝试使用StringBuilder
生成word文档,如下所示
[WebMethod]
public static void ExportToWord(string HTMLContent)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = "application/msword";
string strFileName = "GenerateDocument" + ".doc";
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + strFileName);
System.Text.StringBuilder strHTMLContent = new System.Text.StringBuilder();
strHTMLContent.Append(HTMLContent);
HttpContext.Current.Response.Write(strHTMLContent);
HttpContext.Current.Response.End();
HttpContext.Current.Response.Flush();
}
问题是当我看到下载的文档时,其余页面内容已添加上述<div>
内容
答案 0 :(得分:2)
我在开头错过了Response.Clear
,在最后错过了Response.End()
。