Search code examples
c#openxmlopenxml-sdkoffice-2010

retrieve footnote of word file with openxml


How can retrieve all footnotes of a word file in c# using open xml, i know that we can retrieve the paragraphs with some things like this:

IEnumerable<Paragraph> paragraphs = mainPart.Document.Body.OfType<Paragraph>();

but when i test it for footnotes i just get the null while i know there is some footnotes in my word file.

i have just find this pages to help me on this problem, but they didn't help me:

Footnotes constructor

how can i get all the footnotes and save theme in a list.


Solution

  • Example to get the footnotes:

    FootnotesPart footnotesPart = wordDoc.MainDocumentPart.FootnotesPart;
    if (footnotesPart != null)
    {
        IEnumerable<Footnote> footnotes = footnotesPart.Footnotes.Elements<Footnote>();
        ...
    }