从aspx页面内容转换为MS Word格式

时间:2014-11-19 08:23:04

标签: c# ms-word

Response.ContentType = "application/word";
Response.AddHeader("content-disposition", "inline;filename=TestPage.doc");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this.Page.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());

Response.Write(sw);
Response.End();
Response.Flush();

我正在尝试从aspx页面转换为word格式。当我启动生成的MS Word文件时,它会显示该对话框 装载时出现问题 缺少文件:c:\ Content \ Site.css

看起来无法加载css文件。解决办法是什么。请回复。

1 个答案:

答案 0 :(得分:0)

尝试添加以下标题:

Response.AddHeader("Content-Type: application/vnd.ms-word"); Response.AddHeader("Expires: 0");Response.AddHeader("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 

此致