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
Convert the RTF file to a text file using a word processor. To do this, first open the file in a program such as Microsoft Word or OpenOffice Writer. Select the “Save as” command in the File menu, choose the TXT format in the drop-down menu and click “Save.”
Find a desired location to save the file. From within the Save As Window, find the Save File Type field. Select the drop-down arrow, and change the file from Rich Text Format (rtf) to Word Document (doc). Select Save.
What is an RTF File. This is a cross-platform document file format with better text adjustability than plain text files. This file format allows the user to perform several formatting tasks, such as font sizes and colors, bolding, italics, and others.
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;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With