【发布时间】:2015-02-26 07:31:39
【问题描述】:
我希望能够将模板 word 文档存储在 Sharepoint 中,并将其用作吐出包含注入模板中的数据的 word doc 的基础。
我可以使用以下代码获取我的 word doc 的文本:
SPSite sc = SPContext.Current.Site;
SPWeb web = sc.AllWebs["MySite"];
string contents = web.GetFileAsString("Documents/MyTemplateWord.doc");
web.Dispose();
然后我可以对“内容”变量进行字符串替换。这很好用。
我现在想以 word doc 的形式“打开”这个新内容。
我的代码如下:
string attachment = "attachment; filename=MyWord.doc";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("content-disposition", attachment);
HttpContext.Current.Response.ContentType = "text/ms-word";
HttpContext.Current.Response.Write(outputText);
HttpContext.Current.Response.End();
我遇到了一个错误,不知道如何解决它。
错误:Sys.WebForms.PageRequestManagerParserErrorException:无法解析从服务器接收到的消息。此错误的常见原因是通过调用 Response.Write()、响应过滤器、HttpModules 或启用了服务器跟踪来修改响应。详细信息:'ࡱ> 附近的解析错误
现在显然它在解析“字符串”内容时存在问题。
我做错了什么?我应该这样做吗?
【问题讨论】:
标签: asp.net sharepoint ms-word