How do I convert To Text Format from RTF using ASP.Net?
Asked
Active
Viewed 6,251 times
3
-
2I took the liberty to change your "command" style post into a question. We love to help, but we don't like to be bossed around. – Toon Krijthe Jan 02 '09 at 18:50
1 Answers
4
You have instructions on MSDN
In C#
class ConvertFromRTF
{
static void Main()
{
string path = @"test2.rtf";
//Create the RichTextBox. (Requires a reference to System.Windows.Forms.dll.)
System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox();
// Get the contents of the RTF file. Note that when it is
// stored in the string, it is encoded as UTF-16.
string s = System.IO.File.ReadAllText(path);
// Display the RTF text.
System.Windows.Forms.MessageBox.Show(s);
// Convert the RTF to plain text.
rtBox.Rtf = s;
string plainText = rtBox.Text;
// Display plain text output in MessageBox because console
// cannot display Greek letters.
System.Windows.Forms.MessageBox.Show(plainText);
// Output plain text to file, encoded as UTF-8.
System.IO.File.WriteAllText(@"output.txt", plainText);
}
}

Filip Ekberg
- 36,033
- 20
- 126
- 183
-
This will work in winforms but can cause serious issues in an asp.net application. You can get "Cannot create windows handle" exception – Sam Jul 07 '11 at 14:32
-
@Sam should work if you remove the Windows.Forms.MessageBox-lines. I just quited the entire example. – Filip Ekberg Jul 07 '11 at 15:57