How to remove existing Header and footer

Hi,

How can I remove current header and footer from a word document before applying new header and footer to word document.

I am using document builder class to apply new headers and footers :

            Word.DocumentBuilder builder = new Word.DocumentBuilder(wordDocument);
            Word.Section currentSection = builder.CurrentSection;
            Word.PageSetup pageSetup = currentSection.PageSetup;
            // --- Create header for pages ---
            pageSetup.HeaderDistance = 20;
            builder.MoveToHeaderFooter(Word.HeaderFooterType.HeaderPrimary);
            Word.Tables.Table headertable = builder.StartTable();
            // Clear table borders.
            //builder.CellFormat.ClearFormatting();
            //builder.StartTable().ClearBorders();
            headertable.ClearBorders();
           //My Code
           //My Code

Hi,

I think we can use Section.Clear Method to remove Header and Footer before applying new headers and footers

Section.HeadersFooters.Clear();

@sai537,

Thanks for your inquiry. Yes, Section.HeadersFooters.Clear removes all nodes from this collection and from the document. Please let us know if you have any more queries.