Separate header on first page- but need footer on all pages including first page

Hi,

I am try to add a header only in first page and same footer to all rest of the pages. here is the code I a using: (I have attached input and output files here)

Document doc = new Document("E:\hf-input.docx");
DocumentBuilder builder = new DocumentBuilder(doc);

PageSetup ps = builder.PageSetup;
ps.DifferentFirstPageHeaderFooter = true; 

builder.MoveToHeaderFooter(HeaderFooterType.HeaderFirst);
builder.Write("hello");

doc.Save("E:\hf-output.docx");

If you observe the hf-output.docx file, there is no footer on first page. How can I keep the footer on the first page, though I need the header on first page?

Hi Srinu,

Thanks for your inquiry. Please see the following additions to your code:

Document doc = new Document(MyDir + @"hf-input.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
PageSetup ps = builder.PageSetup;
ps.DifferentFirstPageHeaderFooter = true;
builder.MoveToHeaderFooter(HeaderFooterType.HeaderFirst);
builder.Write("hello");
// Create footer for the first page
HeaderFooter footerFirst = new HeaderFooter(doc, HeaderFooterType.FooterFirst);
doc.FirstSection.HeadersFooters.Add(footerFirst);
// Now copy content of primary footer to the first footer
foreach (Node node in doc.FirstSection.HeadersFooters[HeaderFooterType.FooterPrimary].ChildNodes)
    footerFirst.AppendChild(node.Clone(true));
doc.Save(MyDir + @"out.docx");

I hope, this helps.

Best regards,