Extract text without footnotes

I want to extract the text from a Word document without footnotes. I came across the article here that explains how to do it:
https://docs.aspose.com/words/net/how-to-extract-selected-content-between-nodes-in-a-document/

However, I get an error on this line:

console.WriteLine("ToString() Result: " + doc.ToString(SaveFormat.Text));

It says that no overload method for ToString takes one argument. How do I fix this?

I’ve posted a comment to that page of the documentation, but I’m posting here as well in case this is a better place for answers.

Thanks,

Daniel

Hi Daniel,

Thanks for your inquiry.

Perhaps you’re using an older version of Aspose.Words; as with Aspose.Words 13.5.0, I was unable to reproduce this error on my side. I would suggest you please upgrade to the latest version of Aspose.Words i.e. 13.5.0. You can download it from the following link:
https://releases.aspose.com/words/net

Secondly, to extract document content without Footnote’s text, please try run the following code snippet:

StringBuilder sb = new StringBuilder();
NodeCollection runNodes = doc.GetChildNodes(NodeType.Run, true);
foreach(Run run in runNodes)
if (run.GetAncestor(NodeType.Footnote) == null)
    sb.Append(run.ToString(SaveFormat.Text));

I hope, this helps.

Best regards,

Hi Awais,

Thanks for this. The update solved it. It’s working perfectly now.

So what’s the difference between the method with doc.ToString(SaveFormat.Text) and the method you’ve described above with a stringbuilder?

Best wishes,

Daniel

Hi Daniel,

Thanks for your inquiry. I have attached a sample input document here for your reference. This document contains a Footnote. When you run the code from my previous post, you’ll notice that it extracts the plain text from document without the Footnote’s text. I hope, this helps.

Best regards,

Thanks Awais, that worked perfectly.

Best wishes,

Daniel

Hi Daniel,

Thanks for your feedback. Please let us know any time you have any further queries. We’re always glad to help you.

Best regards,