开发者

How to load a word doc in Rich Textbox WPF

开发者 https://www.devze.com 2023-03-09 20:42 出处:网络
I am trying to load a word document into Rich Textbox control开发者_运维技巧 so that user can edit the contents and eventually save it. Following is the code I use:

I am trying to load a word document into Rich Textbox control开发者_运维技巧 so that user can edit the contents and eventually save it. Following is the code I use:

string fileName = @"..\..\Files\test.doc";

            TextRange range;

            FileStream fStream;

            if (File.Exists(fileName))
            {

                range = new TextRange(RTB.Document.ContentStart, RTB.Document.ContentEnd);

                fStream = new FileStream(fileName, FileMode.OpenOrCreate);

                range.Load(fStream, DataFormats.Rtf);

                fStream.Close();

            }

When I run it I get the following error:

Unrecognized structure in data format 'Rich Text Format'.Parameter name: stream

I have made sure that that document contains no images.


A word document isn't a rich text document.

The doc would need to be first saved as an RTF file before you can do this.

0

精彩评论

暂无评论...
验证码 换一张
取 消