Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

Posted

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.

C#
  • *Experts*
Posted

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.

:)

Posted

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!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...