Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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");

        web.Dispose();

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.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();

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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.