如何使用ASP.Net将Rtf转换为Text?

时间:2022-10-30 14:31:12

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

如何使用ASP.Net从RTF转换为文本格式?

2 个解决方案

#1


You have instructions on MSDN

您有关于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);
    }
}

#2


Not sure it this helps. But otherwise, google is your friend.

不确定这会有所帮助。但除此之外,谷歌是你的朋友。

#1


You have instructions on MSDN

您有关于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);
    }
}

#2


Not sure it this helps. But otherwise, google is your friend.

不确定这会有所帮助。但除此之外,谷歌是你的朋友。