如何读取使用.NET 4.0 .rtf文件 [英] How to read an .RTF file using .NET 4.0

查看:193
本文介绍了如何读取使用.NET 4.0 .rtf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了使用Word 9.0对象库的样本。但我有Office 2010测试版和.NET 4.0在VS2010。如何去与新的Word的dll任何提示?

I have seen samples using Word 9.0 object library. But I have Office 2010 Beta and .NET 4.0 in VS2010. Any tips on how to go with the new Word Dlls?

所以,我只是想获得RTF格式的功能,以文本.NET3.5或更高版本。

So I just wanted to get the functionality of RTF to TEXT with .NET3.5 or later.

推荐答案

我用WPF更好的解决方案,使用的TextRange。

I got a better solution with WPF , using TextRange.

FlowDocument document = new FlowDocument();

//Read the file stream to a Byte array 'data'
TextRange txtRange = null;

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

现在你可以看到里面documentTextRange.Text所提取的文本

Now you can see the extracted text inside documentTextRange.Text

这篇关于如何读取使用.NET 4.0 .rtf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆