<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Remove the headers and footers from a word processing document</title><link>https://sourceforge.net/p/asposeopenxml/wiki/Remove%2520the%2520headers%2520and%2520footers%2520from%2520a%2520word%2520processing%2520document/</link><description>Recent changes to Remove the headers and footers from a word processing document</description><atom:link href="https://sourceforge.net/p/asposeopenxml/wiki/Remove%20the%20headers%20and%20footers%20from%20a%20word%20processing%20document/feed" rel="self"/><language>en</language><lastBuildDate>Tue, 26 May 2015 04:31:42 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/asposeopenxml/wiki/Remove%20the%20headers%20and%20footers%20from%20a%20word%20processing%20document/feed" rel="self" type="application/rss+xml"/><item><title>Remove the headers and footers from a word processing document modified by Aspose Marketplace</title><link>https://sourceforge.net/p/asposeopenxml/wiki/Remove%2520the%2520headers%2520and%2520footers%2520from%2520a%2520word%2520processing%2520document/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v4
+++ v5
@@ -98,4 +98,4 @@

 ## Download ##

-* [Sample Code]()
+* [Sample Code](http://sourceforge.net/projects/asposeopenxml/files/Aspose.Words%20Vs%20OpenXML/RemoveHeaderFooter.zip/download)
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Aspose Marketplace</dc:creator><pubDate>Tue, 26 May 2015 04:31:42 -0000</pubDate><guid>https://sourceforge.net207fe7559a60c6208f6921eff3f347be8e31247e</guid></item><item><title>Remove the headers and footers from a word processing document modified by Aspose Marketplace</title><link>https://sourceforge.net/p/asposeopenxml/wiki/Remove%2520the%2520headers%2520and%2520footers%2520from%2520a%2520word%2520processing%2520document/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Aspose Marketplace</dc:creator><pubDate>Mon, 25 May 2015 19:37:48 -0000</pubDate><guid>https://sourceforge.net764ae1643b429423bcd13842166e7b59d27840f0</guid></item><item><title>Remove the headers and footers from a word processing document modified by Aspose Marketplace</title><link>https://sourceforge.net/p/asposeopenxml/wiki/Remove%2520the%2520headers%2520and%2520footers%2520from%2520a%2520word%2520processing%2520document/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Aspose Marketplace</dc:creator><pubDate>Mon, 25 May 2015 19:37:36 -0000</pubDate><guid>https://sourceforge.netfbf49d36d46d6c9021c0649b35746f4ff94031ad</guid></item><item><title>Remove the headers and footers from a word processing document modified by Aspose Marketplace</title><link>https://sourceforge.net/p/asposeopenxml/wiki/Remove%2520the%2520headers%2520and%2520footers%2520from%2520a%2520word%2520processing%2520document/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v1
+++ v2
@@ -1,4 +1,4 @@
-## OpenXML Word ##
+## OpenXML Words ##

 To use the sample code , you must install the Open XML SDK 2.5. You must then explicitly reference the following assemblies in your project.

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Aspose Marketplace</dc:creator><pubDate>Mon, 25 May 2015 19:37:06 -0000</pubDate><guid>https://sourceforge.netae989a47c8f13152655aa62cb7fb04a9bbf22329</guid></item><item><title>Remove the headers and footers from a word processing document modified by Aspose Marketplace</title><link>https://sourceforge.net/p/asposeopenxml/wiki/Remove%2520the%2520headers%2520and%2520footers%2520from%2520a%2520word%2520processing%2520document/</link><description>&lt;div class="markdown_content"&gt;&lt;h2 id="openxml-word"&gt;OpenXML Word&lt;/h2&gt;
&lt;p&gt;To use the sample code , you must install the Open XML SDK 2.5. You must then explicitly reference the following assemblies in your project.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;WindowsBase&lt;/li&gt;
&lt;li&gt;DocumentFormat.OpenXml (installed by the Open XML SDK)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You must also use the following using directives or Imports statements to compile the code in this topic.&lt;/p&gt;
&lt;p&gt;using System.Linq;&lt;br /&gt;
using DocumentFormat.OpenXml;&lt;br /&gt;
using DocumentFormat.OpenXml.Packaging;&lt;br /&gt;
using DocumentFormat.OpenXml.Wordprocessing;&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;RemoveHeadersAndFooters&lt;/strong&gt; method works with the document you specify, deleting all of the header and footer parts and references to those parts. The code starts by opening the document, using the Open method and indicating that the document should be opened for read/write access (the final true parameter). Given the open document, the code uses the &lt;strong&gt;MainDocumentPart&lt;/strong&gt; property to navigate to the main document, storing the reference in a variable named docPart.&lt;/p&gt;
&lt;p&gt;Given a reference to the document part, the code next determines if it has any work to do─that is, if the document contains any headers or footers. This simple method &lt;strong&gt;DeleteParts&lt;/strong&gt; provides a shortcut for deleting a collection of parts. &lt;/p&gt;
&lt;p&gt;To remove the stranded references, the code first retrieves a collection of &lt;strong&gt;HeaderReference&lt;/strong&gt; elements, converts the collection to a List, and then loops through the collection, calling the &lt;strong&gt;Remove&lt;/strong&gt; method for each element found. &lt;/p&gt;
&lt;p&gt;Below is the code sample&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;    public static void RemoveHeadersAndFooters(string filename)
    {
        // Given a document name, remove all of the headers and footers
        // from the document.
        using (WordprocessingDocument doc =
               WordprocessingDocument.Open(filename, true))
        {
            // Get a reference to the main document part.
            var docPart = doc.MainDocumentPart;
            // Count the header and footer parts and continue if there 
            // are any.
            if (docPart.HeaderParts.Count() &amp;gt; 0 ||
                docPart.FooterParts.Count() &amp;gt; 0)
            {
                // Remove the header and footer parts.
                docPart.DeleteParts(docPart.HeaderParts);
                docPart.DeleteParts(docPart.FooterParts);

                // Get a reference to the root element of the main
                // document part.
                Document document = docPart.Document;

                // Remove all references to the headers and footers.

                // First, create a list of all descendants of type
                // HeaderReference. Then, navigate the list and call
                // Remove on each item to delete the reference.
                var headers =
                  document.Descendants&amp;lt;HeaderReference&amp;gt;().ToList();
                foreach (var header in headers)
                {
                    header.Remove();
                }

                // First, create a list of all descendants of type
                // FooterReference. Then, navigate the list and call
                // Remove on each item to delete the reference.
                var footers =
                  document.Descendants&amp;lt;FooterReference&amp;gt;().ToList();
                foreach (var footer in footers)
                {
                    footer.Remove();
                }

                // Save the changes.
                document.Save();
            }
        }
    }
&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id="asposewords"&gt;Aspose.Words&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Aspose.Words&lt;/strong&gt; provide API for header and footer of MS Word document. We can use &lt;strong&gt;Section.HeadersFooters&lt;/strong&gt; property to get the collection of header/footer in a section of document. &lt;strong&gt;HeaderFooter&lt;/strong&gt; class represents a container for the header or footer text of a section. &lt;strong&gt;HeaderFooter&lt;/strong&gt; can contain Paragraph and Table child nodes.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;HeaderFooter&lt;/strong&gt; is a section-level node and can only be a child of Section. There can only be one &lt;em&gt;HeaderFooter&lt;/em&gt; or each &lt;strong&gt;HeaderFooterType&lt;/strong&gt; in a Section.&lt;/p&gt;
&lt;p&gt;Below is  the sample code to remove header and footer from Word Document.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;        Document doc = new Document(RemoveHeaderFooter.docx);
        foreach (Section section in doc)
        {
            section.HeadersFooters.RemoveAt(0);
            HeaderFooter footer;
            // Primary footer is the footer used for odd pages.
            footer = section.HeadersFooters[HeaderFooterType.FooterPrimary];
            if (footer != null)
                footer.Remove();
        }
       doc.Save(RemoveHeaderFooter.docx);
&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id="download"&gt;Download&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="../"&gt;Sample Code&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Aspose Marketplace</dc:creator><pubDate>Mon, 25 May 2015 19:26:00 -0000</pubDate><guid>https://sourceforge.neta933f07230dbae5af4c65ca4753ea1d41e7db5a8</guid></item></channel></rss>