How to read an .RTF file using .NET 4.0

Do you really new to load .RTF into Word? .net has RichTextBox control that can handle .RTF files. See here: http://msdn.microsoft.com/en-us/library/1z7hy77a.aspx (How to: Load Files into the Windows Forms RichTextBox Control)


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