Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read an .RTF file using .NET 4.0

I have seen samples using Word 9.0 object library. But I have Office 2010 Beta and .NET 4.0 in VS2010. Any tips on how to go with the new Word Dlls?

So I just wanted to get the functionality of RTF to TEXT with .NET3.5 or later.

like image 809
Jobi Joy Avatar asked Feb 19 '10 07:02

Jobi Joy


1 Answers

I got a better solution with WPF , using TextRange.

FlowDocument document = new FlowDocument();

//Read the file stream to a Byte array 'data'
TextRange txtRange = null;

using (MemoryStream stream = new MemoryStream(data))
{
    // create a TextRange around the entire document
    txtRange = new TextRange(document.ContentStart, document.ContentEnd);
    txtRange.Load(stream, DataFormats.Rtf);
}

Now you can see the extracted text inside documentTextRange.Text

like image 122
Jobi Joy Avatar answered Oct 13 '22 00:10

Jobi Joy