SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to be able to store a template word document in SharePoint 2007, and use it as a base for spitting out a word doc containing data injected into the template.

I can get the text of my word doc using code as follows:

        SPSite sc = SPContext.Current.Site;
        SPWeb web = sc.AllWebs["MySite"];            

        string contents = web.GetFileAsString("Documents/MyTemplateWord.doc");


Then I can string replace on the "contents" variable. This works fine.

I now want to "open" this new content as a word doc.

My code for this is as follows:

       string attachment = "attachment; filename=MyWord.doc";
        HttpContext.Current.Response.AddHeader("content-disposition", attachment);
        HttpContext.Current.Response.ContentType = "text/ms-word";

I'm getting an error though, and not sure how to resolve it.

Error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled. Details: Error parsing near 'ࡱ>

Now clearly it has issues parsing the "string" content.

What am I doing wrong? Is there a different way I should be doing this?

share|improve this question

Here is a recent SP.SE post where someone wanted to manipulate a document when it was opened, it might give you some ideas.

share|improve this answer
thanks I'll check it out! – ozz Nov 29 '11 at 9:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.