Get plain text from an RTF text

rpf picture rpf · Feb 27, 2009 · Viewed 20.2k times · Source

I have on my database a column that holds text in RTF format.

How can I get only the plain text of it, using C#?

Thanks :D

Answer

Daniel LeCheminant picture Daniel LeCheminant · Feb 27, 2009

Microsoft provides an example where they basically stick the rtf text in a RichTextBox and then read the .Text property... it feels somewhat kludgy, but it works.

static public string ConvertToText(string rtf)
{
   using(RichTextBox rtb = new RichTextBox())
   {
       rtb.Rtf = rtf;
       return rtb.Text;
   }
}