masj78 Posted September 17, 2003 Posted September 17, 2003 I have written a routine to save text from a RichTextBox to a file. The text is taken from Outlook and contains the original formating. However I am loosing the formating when saving it to a .TXT file and wondering if its possible to ajust my code to save it as a .DOC instead. (would save an extra cut and paste into Wordpad/Word or openwith ....) My code is as follows: SaveFileDialog1.Filter = "Text files(*.txt)|*.txt" SaveFileDialog1.ShowDialog() If SaveFileDialog1.FileName <> "" Then FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output) PrintLine(1, RichTextBox1.Text) FileClose(1) End If Many Thanks!:rolleyes: Quote
aewarnick Posted September 17, 2003 Posted September 17, 2003 I think if you copy the formatted text from Outlook into the clipboard then paste it in the RTB it will work. Then you just use the save method of the RTB to keep the formatting. I believe you can then give it the extention of doc. Quote C#
*Experts* mutant Posted September 17, 2003 *Experts* Posted September 17, 2003 Use the SaveFile and LoadFile methods of the RTB. Also I would suggest using IO.StremReader for reading and IO.StreamWriter for writing, they are part of the framework and better then the old vb6 methods. :) Quote
masj78 Posted September 18, 2003 Author Posted September 18, 2003 Many Thanks for the advice. I have chosen to use the RTB methods, which has taken a fraction of the code and saves the files with no loss of formating: Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click SaveFileDialog1.Filter = "Text files(*.doc)|*.doc" SaveFileDialog1.ShowDialog() emailText.SaveFile(SaveFileDialog1.FileName,OpenMode.Output) End Sub cheers! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.