开发者

c# Richtext box can not load rtf file while Microsoft word using that file

开发者 https://www.devze.com 2023-01-28 14:46 出处:网络
i used a read stream to read an rtf file how开发者_运维技巧ever it failed when this rtf file is opened byMicrosoft word.

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)
0

精彩评论

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