我希望能够在Sharepoint中存储模板word文档,并将其用作吐出包含注入到模板中的数据的word文档的基础。从sharepoint打开word文档,替换文本和流到用户
我可以使用代码如下得到我的Word文档的文本:
SPSite sc = SPContext.Current.Site;
SPWeb web = sc.AllWebs["MySite"];
string contents = web.GetFileAsString("Documents/MyTemplateWord.doc");
web.Dispose();
然后,我可以串在“内容”变量替换。这工作正常。
我现在想“打开”这个新的内容作为word文档。
我给这家代码如下:
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或服务器跟踪已启用来修改响应时。详细信息:错误解析'ࡱ>
现在很明显,它有解析“字符串”内容的问题。
我在做什么错?有没有不同的方式我应该这样做?