How to get the text content from MS Word document and assign to a string in C#

I have the path to my file and I just want to get the text from the file and assign in to a string.How can I do that?

Hi Kristian,

Thanks for your inquiry. Please refer to the following section of the documentation which outlines everything you need to know about extracting Text from document:
How to Extract Text Only

Please let me know if I can be of any further assistance.

Best regards,

The link you provided is not working . Can you provide another link to extract Text content from a Word Document using c#

Hi Rajesh,

Thanks for your inquiry. The broken link in my previous post has now been fixed. You can use the following ways to retrieve text from the document:

  • Use Document.Save with SaveFormat.Text to save as plain text into a file or stream.
  • Use Node.ToString and pass the SaveFormat.Text parameter. Internally, this invokes save as text into a memory stream and returns the resulting string.
  • Use Node.GetText to retrieve text with all Microsoft Word control characters including field codes.
  • Implement a custom DocumentVisitor to perform customized extraction.
Document doc = new Document(MyDir + @"in.docx");
TxtSaveOptions opts = new TxtSaveOptions();
doc.Save(MyDir + @"out.txt", opts);

Hope, this helps.

Best regards,