【问题标题】:How do I convert Rtf to Text using ASP.Net?如何使用 ASP.Net 将 Rtf 转换为文本?
【发布时间】:2009-01-02 18:46:27
【问题描述】:

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

【问题讨论】:

  • 我冒昧地将您的“命令”风格帖子更改为问题。我们喜欢提供帮助,但我们不喜欢被人左右。

标签: asp.net text rtf


【解决方案1】:

您有关于MSDN的说明

在 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);
    }
}

【讨论】:

  • 这将在 winforms 中工作,但会在 asp.net 应用程序中导致严重问题。你可以得到“无法创建窗口句柄”异常
  • @Sam 如果您删除 Windows.Forms.MessageBox 行应该可以工作。我刚刚完成了整个示例。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-09-29
  • 1970-01-01
  • 1970-01-01
  • 2015-05-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多