We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

MethodWhichWillResultTheEntireContent, header footer

WordDocument wordDokument = new WordDocument();
wordDokument.Open(someStream, FormatType.Docx);
wordDokument.Replace("someString", MethodWhichWillResultTheEntireContent(), false, false);
IWSection section = wordDokument.AddSection();
IWParagraph tableHeaderParagraph = section.HeadersFooters.Header.AddParagraph();

For example "MethodWhichWillResultTheEntireContent()" has may be 10 pages, but when I insert Header/Footer it will append it to the last document and not all pages(including from "MethodWhichWillResultTheEntireContent()").

How can I set header and footer for pages including which come from "MethodWhichWillResultTheEntireContent()" ?

6 Replies

PE Priyanga Elangovan Syncfusion Team October 13, 2016 07:05 AM UTC

Hi Customer,

Thank you for contacting Syncfusion support.

On further analyzing on the given code snippet, we found that you are replacing the Word document content using WordDocument.Replace method, after that you have added the new section to the Word document and set the headerfooter for this newly added section. So that, the headerfooter contents are preserved only for the pages in that newly added section. If your requirement is to set the headerfooter for all the pages in the document means, then you need to set the headerfooter for the lastsection of the document before adding the new section to the document. We have prepared the sample to illustrate the same. Please find the sample from below link.

Sample Link:

As per the Microsoft Word behaviour Essential DocIO supports the following header footer types.

      1. First Page Header and First Page Footer
      2. Odd Header and Odd Footer
      3. Even Header and Even Footer

You can make use of the above header footer types using DocIO. Kindly refer the below UG documentation link to know more about Header and Footers.

UG documentation link:



NT New Tester October 13, 2016 08:43 AM UTC

"Default1Controller.cs" is not avaiable in the solution, but even I take a look at the file in the folder, there is actually no reference to my requst.

No my code looks like this:

        private void InitMethod()

            WordDocument word = new WordDocument();
            word.Open(someStream, FormatType.Docx);
            word.Replace("someString", MethodWhichWillResultTheEntireContent(), false, false);


        private WordDocument MethodWhichWillResultTheEntireContent()

            WordDocument word = new WordDocument();


            WParagraph p1 = word.LastSection.AddParagraph() as WParagraph;
            WParagraph p1graph = word.LastSection.HeadersFooters.Header.AddParagraph() as WParagraph;
            p1graph.AppendText("Header footer");//this is NOT visible in the document

            p1.AppendText("first page"); //this is visible in the document

            return word;
Right now I do not even get the header/footer.

VR Vijay Ramachandran Syncfusion Team October 13, 2016 01:30 PM UTC

Hi Customer,

Thank you for your information.

As per the behaviour of WordDocument.Replace() method, it replaces the text with document text body items only and it won’t replace the sections header footer. So that the header and footer contents are not copied to the source document.

Kindly provide confirmation on whether your requirement is adding same header and footer contents to all of the pages in result Word document or only at particular section headers and footers which have the replacing text and also provide the input Word document along with complete code snippets. So that we can analyse further and provide you the appropriate solution as much early as possible.

Vijay R

NT New Tester October 13, 2016 02:14 PM UTC

"adding same header and footer contents to all of the pages in result Word document". thanks

VR Vijay Ramachandran Syncfusion Team October 14, 2016 05:37 AM UTC

Hi Customer,

Thank you for your update.

We have prepared the sample as per your requirement, in this sample we have replaced the particular text with new word document which have multiple pages using
WordDocument.Replace() method. After that to preserve the header and footer in each page, we have iterated all the sections in the source Word document and added the text for each section header footers. Please find the sample from the below link:

Let us know if you have any concern.

Vijay R

NT New Tester October 14, 2016 08:09 AM UTC

thank you :)

Live Chat Icon For mobile
Up arrow icon