Reputation: 263
i used a read stream to read an rtf file however it failed when this rtf file is opened by Microsoft word.
is there anyone know how to solve this problem?
Upvotes: 0
Views: 510
Reputation: 887469
Like this:
new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
Upvotes: 1
Reputation: 55573
The proper way to read a RTF file for a rich text box (has to be of type System.Windows.Forms.RichTextBox) is like this:
myRichTextBox.LoadFile(myFilename);
But, because you have a lock on the file, you have to do it this way (credit to @slaks):
myRichTextBox.LoadFile(new FileStream(myFilename, FileAccess.Read, FileSharing.ReadWrite));
And to save it, simply call this function:
myRichTextBox.SaveFile(myFilename);
Upvotes: 1