How to read from and write to a .rtf or a .doc file?
Posted on 2005-03-30
I have an app that I need to read in text from a .rtf or .doc file and write to the same file. I need it to be able to read and write bolded words and other formatting done to words.
Right now I can get it to read and write to a .txt file but it doesn't read in or write any bolding and formatting done to words.
So intead of reading from a text file file I tried a .rtf file and a .doc file. Reading them into my richTextBox of my app I get a bunch of garbage before the text.
I have a button to read from the file and a button to write to the file.
Here is the code that I am currently using for this.
Dim read As String
Dim sr As New StreamReader("c:\test.doc")
RichTextBox1.Text = sr.ReadToEnd
Dim Write As String
Dim sw As New StreamWriter("c:\test.doc", False)
Write = Trim(RichTextBox1.Text)