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.
DsWord 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.
To add a footnote and endnote:
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"); |
To modify a footnote and endnote:
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"); |
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"); |
To set numbering style of footnotes and endnotes:
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"); |
For more information on how to implement footnotes and endnotes in a Word document using DsWord, see DsWord sample browser.