質問

さらに解析するには、RTFドキュメントをFlowDocumentにインポートする必要があります。しかし、非常に奇妙な問題があります:

public string ConvertRTF(byte[] bytes)
{
    if (bytes == null)
    {
        throw new ArgumentNullException();
    }

    FlowDocument document = new FlowDocument();

    // open the file for reading
    using (MemoryStream stream = new MemoryStream(bytes, true))
    {
        // create a TextRange around the entire document
        TextRange documentTextRange = new TextRange(document.ContentStart, document.ContentEnd);
        if (documentTextRange.CanLoad(DataFormats.Rtf))
            documentTextRange.Load(stream, DataFormats.Rtf);
    }

    return XamlWriter.Save(document);

}

このメソッドを3つの異なるプロジェクトでテストしました:

  • Wpfスタンドアロンアプリ:これまでのところ何の問題もありませんが、残念ながら、この種のアプリケーションは使用できません。
  • コンソールアプリ:多くの場合機能しますが、時々画像のあるドキュメントで破損し、破損したときに指を動かすことができません。理由...受け取ったエラーTextRangeのLoadメソッドにあります:"データ形式 'Rich Text Format'の認識されない構造。パラメーター名:stream"
  • Xbapアプリケーション:CanLoadメソッドを通過しません... :(だから結果としてwhathisnameをジャックします...

重要なことは、コンソールアプリでテストすると、次の構成でエラーなしで動作することです。

[STAThread]
static void Main(string[] args)
{
    OpenFileDialog dialog = new OpenFileDialog
    {
        Filter = "import files (*.rtf)|*.rtf"
    };

    if (dialog.ShowDialog() != DialogResult.OK)
        return;


    byte[] data;
    using (Stream filestream = dialog.OpenFile())
    {
        int offset = 0;
        data = new byte[filestream.Length];
        int remaining = data.Length;
        while (remaining > 0)
        {
            int read = filestream.Read(data, offset, remaining);
            if (read <= 0)
                throw new EndOfStreamException
                    (String.Format("End of stream reached with {0} bytes left to read", remaining));
            remaining -= read;
            offset += read;
        }
    }

    FlowDocument document = new FlowDocument();

    using (MemoryStream stream = new MemoryStream(data))
    {
        // create a TextRange around the entire document
        TextRange documentTextRange = new TextRange(document.ContentStart, document.ContentEnd);
        documentTextRange.Load(stream, DataFormats.Rtf);
    }

    Console.WriteLine("test ok");
}

これはまさに私を無知にしますが、それはまさに私がやっていることですが、その後2つのステップで段階的に行われます...最初にビットを取得し、次にメモリストリームを使用してRTFにします...:(

一部のdllバージョンで何らかの理由で競合が発生している可能性がありますか?プロジェクトに3.5 SP1を使用しています...

上記の最後の2つの可能性のいずれかの解決策を見つけるのを手伝ってくれますか?

ありがとう

役に立ちましたか?

解決 2

明らかにできません。

最終的には、rtfをより多くの特権を持つサーバーに送信し、結果をクライアントに送り返します。厄介ですが、動作します。

他のヒント

信頼レベルに問題がある可能性があります。 Xbapインターネットアプリケーションは、部分信頼のデフォルト設定です。証明書を使用して、xpabインターネットアプリケーションとの完全な信頼を許可できます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top