Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert Rtf to Text using ASP.Net?

Tags:

text

asp.net

rtf

How do I convert To Text Format from RTF using ASP.Net?


1 Answers

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);
    }
}
like image 65
Filip Ekberg Avatar answered Dec 07 '25 09:12

Filip Ekberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!