Hi,
Response.ContentType = "application/word"; Response.AppendHeader("Content-Disposition", string.Format("attachment; filename={0}_Final_Entry.doc", "contractoc"));
// here I need to add header and footer for word.. Anyone help me
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Lorine ApplebyPosted Dec 19, 2014, 5:26 AM
Ok so if I understood you correctly you want to download your Word document but before you stream it to a client you want to add some custom header and footer.
Well the first question is where that document of yours is, does that "contractoc_Final_Entry.doc" file even exist?
Second I do not know why 'Jaganathan' thinks you want to save your response as a DOC file, the code that you provided does not indicate that, actually it does not provide much information at all. The only thing it shows is that you are defining the MIME type of the current response, so I can only presume that you want to execute a downloading of a word file.
But if 'Jaganathan' is right and you are actually trying to save your page as a word document then I'm afraid you cannot add header and footer to it. You see there is a common workaround in which developers would use a HTML content and save it to a file that has a word document extension. The trick is that most of the Word applications will be able to open this file, but it is not actually a word document at all. So I'm guessing that you are maybe using that workaround and if so note that you actually have a HTML file (with a DOC extension) and these files do not have a page header and page footer concepts.
So what you need to do is to convert the HTML content into a Word file in C# and then you will be able to add your header and footer:
I used this C# component for manipulating with Word files because you also have an easy way how you can export a Word document in ASP.NET, with a single line so you can remove the line that you posted and just use this:
Regards
Jaganathan BantheswaranPosted Jan 10, 2014, 2:22 AM
within body,
This is the Title of the Content
Some text
Raja APosted Jan 10, 2014, 12:58 AM
Jaganathan BantheswaranPosted Jan 9, 2014, 4:53 AM
You are trying to save the HTTP response as doc file. So whatever there in the response [document] will be saved as doc. If you want to add header or footer, you have to add it on the document/html page.
Raja APosted Jan 9, 2014, 3:07 AM
Ayin RiveraPosted Jan 9, 2014, 2:55 AM