Как преобразовать RTF в текст с помощью ASP.Net?

Как преобразовать в текстовый формат из RTF с помощью ASP.Net?


person Community    schedule 02.01.2009    source источник
comment
Я взял на себя смелость изменить ваш пост в командном стиле на вопрос. Мы любим помогать, но не любим, когда нами командуют.   -  person Toon Krijthe    schedule 02.01.2009


Ответы (1)


У вас есть инструкции на 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);
    }
}
person Filip Ekberg    schedule 02.01.2009
comment
Это будет работать в winforms, но может вызвать серьезные проблемы в приложении asp.net. Вы можете получить Невозможно создать исключение дескриптора Windows - person Sam; 07.07.2011
comment
@Sam должен работать, если вы удалите строки Windows.Forms.MessageBox. Я только что закончил весь пример. - person Filip Ekberg; 07.07.2011