How to remove footnote from word document in C#

Footnotes are the notes in the text of the document paper by using consecutive superscript numbers. The actual information is listed at the bottom of the page. With the help of Spire.Doc, we can easily add the footnote to the word document in C# and VB.NET. This article will show you how to remove the footnote from word document in C#.

Firstly, please view the original word document with footnote.

How to remove footnote from word document in C#

Note: Before Start, please download the latest version of Spire.Doc and add Spire.Doc.dll in the bin folder as the reference of Visual Studio.

Here comes to the steps of how to remove the footnote from word document.

Step 1: Create a new word document and load a file with footnote.

Document document = new Document();
document.LoadFromFile("Sample.docx");

Step 2: Get the first section for the document.

Section section = document.Sections[0];

Step 3: Find the footnote object and remove it.

foreach (Paragraph para in section.Paragraphs)
{
    int index = -1;
    for (int i = 0, cnt = para.ChildObjects.Count; i < cnt; i++)
    {
        ParagraphBase pBase = para.ChildObjects[i] as ParagraphBase;
        if (pBase is Footnote)
        {
            index = i;
            break;
        }
    }

    if (index > -1)
        para.ChildObjects.RemoveAt(index);
}

Step 4: Save the document to file.

document.SaveToFile("result.docx", FileFormat.Docx);

Effective screenshot after remove the footnote from the word document:

How to remove footnote from word document in C#

Full codes:

static void Main(string[] args)
 {

     Document document = new Document();
     document.LoadFromFile("Sample.docx");
     Section section = document.Sections[0];

     foreach (Paragraph para in section.Paragraphs)
     {
         int index = -1;
         for (int i = 0, cnt = para.ChildObjects.Count; i < cnt; i++)
         {
             ParagraphBase pBase = para.ChildObjects[i] as ParagraphBase;
             if (pBase is Footnote)
             {
                 index    = i;
                 break;
             }
         }

        if (index > -1)
           para.ChildObjects.RemoveAt(index);
     }

     document.SaveToFile("result.docx", FileFormat.Docx);

}