I want to extract the text from a Word document without footnotes. I came across the article here that explains how to do it:
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 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:
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)
I hope, this helps.
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?
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.
Thanks Awais, that worked perfectly.
Thanks for your feedback. Please let us know any time you have any further queries. We’re always glad to help you.