Recursive AI

Add footnotes to a Word document in C#

OneDocument is a free, open-source Word, Excel and PowerPoint document library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

Terminal
dotnet add package RecursiveAI.OneDocument.Documents

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

C#
using RecursiveAI.OneDocument
    .Documents;
 
using var doc = Document.Create();
var text = doc.Body.AddParagraph("Claim.");
doc.Footnotes.Add("Source.")
    .AppendReference(text);
doc.SaveAs("notes.docx");

Writes notes.docx with a footnote attached to “Claim.” The snippet prints no console output.

Unzip the example, then dotnet run.

Full program

The full example creates its own input: a paragraph reading “Revenue rose.” and the footnote “Source: annual report.” It saves and reopens the file, lists separators separately from normal notes, then removes the normal note and saves without-notes.docx.

C#
using RecursiveAI.OneDocument.Documents;
using RecursiveAI.OneDocument.Documents.Notes;
 
using var doc = Document.Create();
var paragraph = doc.Body.AddParagraph("Revenue rose.");
var note = doc.Footnotes.Add("Source: annual report.");
note.AppendReference(paragraph);
doc.SaveAs("notes.docx");
Console.WriteLine("Wrote notes.docx");
using var reopened = Document.Open("notes.docx");
foreach (var item in reopened.Footnotes)
    Console.WriteLine($"{item.Id}: {item.Type}: {item.Text}");
var normal = reopened.Footnotes.Single(n => n.Type == NoteType.Normal);
Console.WriteLine($"References: {normal.References().Count}");
reopened.Footnotes.Remove(normal);
reopened.SaveAs("without-notes.docx");
Console.WriteLine($"Normal notes left: {reopened.Footnotes.Count(n => n.Type == NoteType.Normal)}");
Console.WriteLine($"References left: {reopened.NoteReferences(NoteKind.Footnote).Count}");
Text
Wrote notes.docx
-1: Separator: 
0: ContinuationSeparator: 
1: Normal:  Source: annual report.
References: 1
Normal notes left: 0
References left: 0

For this generated document, the first note has ID 1; the two empty entries are separator notes, not missing source text. Removing a separator or trying to reference one throws InvalidOperationException.

Variations

Edit the text of an existing footnote. Run this after the full program.

C#
using RecursiveAI.OneDocument.Documents;
using RecursiveAI.OneDocument.Documents.Notes;
 
using var doc = Document.Open("notes.docx");
var note = doc.Footnotes.Single(n => n.Type == NoteType.Normal);
note.SetText("Revised source.");
doc.SaveAs("revised.docx");
Console.WriteLine(note.Text.Trim());
Text
Revised source.

The short answer

Use Document.Footnotes.Add(text) to create the note and AppendReference(paragraph) to attach its reference to the body. Save as DOCX. These are two distinct operations: creating note text alone does not place a reference in a paragraph.

The example also reopens the saved document so you can inspect the note that was actually written. A note’s ID connects it to references; it is not a promise that the displayed number always equals that ID. Numbering settings and the reading application determine the displayed mark.

How do I insert footnotes into a Word document?

Start with the paragraph that needs the citation. Add the footnote to the document’s collection, then append its reference to that paragraph. To put a reference beside a particular run rather than at the paragraph’s end, the note API also offers InsertReference(run).

A document without a footnotes part starts with an empty collection. Adding the first note creates the part, its relationship and content type, and separator and continuation-separator notes. If a settings part exists, the separator IDs are added there too. The notes documentation describes these package changes.

Do not count every entry in Footnotes as a citation. Filter by NoteType.Normal, as the full program does. Separator entries describe the boundary between body text and the notes area. They are intentionally visible in the collection so an editor does not silently lose them.

A footnote is linked to a particular place in the document body by a reference mark. A footer is a separate story associated with a section’s pages. Use footnotes for citations or explanations attached to a claim; use footer content for page-level text. They are separate structures in OneDocument: Footnotes is not a way to add a footer.

Footnotes also differ from comments. A note supplies document content; comments are review annotations with authors and ranges. The note API does not turn a citation into a discussion thread. Microsoft’s footnote instructions explain the reference-mark workflow in Word itself.

How do I edit a footnote in Word?

Find the normal note you intend to change, then call SetText. The variation updates the generated example’s only normal note; on a real document, select the note by its ID or its reference rather than assuming there is only one.

SetText keeps the first paragraph’s properties and automatic number mark, but replaces the rest of the note content with one text run. It is therefore a text replacement, not an operation that preserves a multi-paragraph note’s internal formatting. If you need that formatting, edit its blocks and runs instead.

Footnotes.Remove(note) removes both the note and its body references. The full program prints both remaining normal notes and remaining references so the two effects are visible.

How do I add a footnote number in Word?

Use the automatic reference rather than inserting a literal superscript digit. The note starts with an automatic number mark; references use the defined character style when available and superscript otherwise.

Document-wide and section-level NoteNumbering settings expose number format, start, restart and position. The documented combination rule is section over document over defaults. This recipe does not change those settings when editing a note. Saving the DOCX preserves the note structure; it does not establish identical pagination to desktop Word. Check page placement in the application that will display or print your document.

All onedocument recipes