c# Richtext box can not load rtf file while Microsoft word using that file
i used a read stream to read an rtf file how开发者_运维技巧ever it failed when this rtf file is opened by Microsoft word.
is there anyone know how to solve this problem?
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);
Like this:
new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
精彩评论