代码之家  ›  专栏  ›  技术社区  ›  Arcturus

在xbap中导入带有图像的RTF

  •  1
  • Arcturus  · 技术社区  · 16 年前

    我需要将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);
    
    }
    

    • Wpf独立应用程序
    • Xbap应用程序 :甚至没有通过CanLoad方法…:(因此,杰克给了我这个名字。。。

    有意思的是,当我用console应用程序测试它时,它在以下构造中工作正常:

    [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");
    }
    

    在某些dll版本中是否可能存在冲突?我们正在为我们的项目使用3.5 SP1。。。

    有人能帮我找到上面提到的最后两种可能性之一的解决方案吗?

    2 回复  |  直到 16 年前
        1
  •  0
  •   tolppa    14 年前

    您可能在信任级别方面存在问题。Xbap Internet应用程序默认为部分信任。您可以使用证书来允许完全信任xpab internet应用程序。

        2
  •  0
  •   Arcturus    14 年前

    我们最终将rtf发送到具有更多权限的服务器,并将结果发送回客户端。很恶心,但它很管用。

    推荐文章