Documents for Word .NET Edition
Features / Footnote and Endnote
In This Topic
    Footnote and Endnote
    In This Topic

    The purpose of using footnotes and endnotes in a document is to explain or provide additional information in a document like a reference or credits to something or someone mentioned in a document. The difference between footnotes and endnotes is that a footnote is displayed at the bottom of each page of a document and endnote appears at the end of a section or a document.

    GcWord allows you to add a footnote and endnote using Add method of the FootnoteCollection class and EndnoteCollection class respectively. It lets you set the footnote and endnote position, numbering rule and number style for a document or a section using the FootnoteOptions and EndnoteOptions class respectively. These classes can be accessed using FootnoteOptions and EndnoteOptions properties of the Settings class respectively.

    Word document with a footnote and an endnote

    Add Footnote and Endnote

    To add a footnote and endnote:

    1. Set the footnote and endnote options using the FootnoteOptions property and the EndnoteOptions property respectively.
    2. Access a content object to which a footnote and endnote needs to be added. For example, access a section of the document.
    3. Add a footnote using Add method of the FootnoteCollection class.
    4. Add an endnote using Add method of the EndnoteCollection class.
      C#
      Copy Code
      doc.Load("HeaderFooter.docx");
      
      //Set footnote options
      doc.Settings.FootnoteOptions.Location = FootnoteLocation.BottomOfPage;
      doc.Settings.FootnoteOptions.NumberingRule = FootnoteNumberingRule.Continuous;
      
      //Add footnote in first section
      var section = doc.Body.Sections.First;                      
      section.GetRange().Paragraphs.First.GetRange().Footnotes.Add("This is a test footnote.");
      
      //Add footnote in second section
      var section2 = doc.Body.Sections[1];
      var secondRun = section2.GetRange().Paragraphs.First.GetRange().Runs.Insert(InsertLocation.End);
      secondRun.GetRange().Texts.Add("This is a reference text for a footnote.");
      secondRun.GetRange().Footnotes.Add("Footnote for second section");
                  
      //Set endnote options
      doc.Settings.EndnoteOptions.Location = EndnoteLocation.EndOfDocument;
      doc.Settings.EndnoteOptions.NumberingRule = EndnoteNumberingRule.Continuous;
      
      //Add endnote at the end of the document
      section.GetRange().Paragraphs[1].GetRange().Endnotes.Add("This is a test endnote.");
      
      //Save the document
      doc.Save("AddNotes.docx");
    Back to Top

    Modify Footnote and Endnote

    To modify a footnote and endnote:

    1. Modify the footnote and endnote option using the FootnoteOptions property and the EndnoteOptions property respectively. For example, modify the location.
    2. Access the footnote and endnote which needs to be modified. For example, access the first footnote and endnote added to the document.
    3. Modify text of the footnote and endnote added to the document using Value property of the Text class.
      C#
      Copy Code
      doc.Load("AddNotes.docx");
      
      //Modify footnote options
      doc.Settings.FootnoteOptions.Location = FootnoteLocation.EndOfSection;            
      
      //Modify the footnote in first section
      var section = doc.Body.Sections.First;
      section.GetRange().Paragraphs.First.GetRange().Footnotes.First.Body.Texts.First.Value = "This" +
          " is a modified test footnote.";
      
      //Modify endnote  
      doc.Settings.EndnoteOptions.Location = EndnoteLocation.EndOfSection;
      
      //Modify the endnote in first section
      section.GetRange().Paragraphs[1].GetRange().Endnotes.First.Body.Texts.First.Value = "This" +
          " is a modified test endnote.";
      
      //Save the document
      doc.Save("ModifyNotes.docx");
    Back to Top

    Delete Footnote and Endnote

    To delete a footnote and endnote, access the footnote and endnote and delete them using Delete method of the ContentObject class.

    C#
    Copy Code
    doc.Load("AddNotes.docx");
    
    //Add footnote in first section.
    var section2 = doc.Body.Sections[1];
    section2.GetRange().Paragraphs.First.GetRange().Footnotes.First.Delete();
    
    //Delete EndNote
    var section = doc.Body.Sections.First;
    section.GetRange().Paragraphs[1].GetRange().Endnotes.First.Delete();
    
    //Save the document
    doc.Save("DeleteNotes.docx");
    Back to Top

    Set Numbering Style

    To set numbering style of footnotes and endnotes:

    1. Access the footnote and endnote options using the FootnoteOptions and EndnoteOptions property respectively.
    2. Set the numbering style for the footnotes and endnotes using NumberStyle property of the FootnoteOptions and EndnoteOptions class respectively, which takes value from the NumberStyle enumeration.
      C#
      Copy Code
      doc.Load("AddNotes.docx");
      
      //Set footnote numbering style
      doc.Settings.FootnoteOptions.NumberStyle = NumberStyle.DecimalEnclosedCircle;
      
      //Set endnote numbering style            
      doc.Settings.EndnoteOptions.NumberStyle = NumberStyle.NumberInDash;
      
      //Save the document
      doc.Save("SetNumbering.docx");
    Back to Top

    For more information on how to implement footnotes and endnotes in a Word document using GcWord, see GcWord sample browser.