Remove Header and Footer in Word using C#

This article guides how to remove header and footer in Word using C#. It has the resources required to configure the IDE, a list of steps defining the process, and a runnable sample code to remove footer in Word using C#. You will learn to remove all the headers and footers without any filters or remove the selected headers and footers based on the first page, even pages, odd pages, and primary headers or footers.

  1. Set the IDE to use Aspose.Words for .NET to remove headers and footers
  2. Load the Word file into a Document object having different types of headers and footers
  3. Parse all the sections in the document
  4. Remove the desired HeadersFooters using the HeaderFooterType from each section
  5. Save the output Word file after removing headers and footers

These steps cover the details on how to delete header and footer in Word using C#. You may start the process by loading the Word file into the Document class and iterate through all the sections. For each section, either call the Clear() method to remove all the headers and footers or access the individual before removing them.

This code segment assists with how to remove footer in Word using C# or headers if required. You can remove selected headers or footers using the HeaderFooterType enumerator; if the first page is different, then use the HeaderFirst/FooterFirst option, if different even/odd pages are there, use HeaderPrimary/FooterPrimary for odd pages and HeaderEven/FooterEven for even pages. To remove all, empty the HeadersFooters collection of the section by calling the Clear() method.

This article has explained removing headers and footers from a Word document. To remove blank pages from a Word file, refer to the article on how to remove blank page in Word using C#.

 English