How to load a word doc in Rich Textbox WPF
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.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论