Member Avatar

Hello, I have problem in one of my program,it's almost a copycat of MS-World, that means it's using RichTextBox, I have Bold,Italic,Underline etc. buttons but when I save the file and open it, it's a basic text that you can get from Notepad.

File Type: DTX
Save Method: Writer (User-made save prompt)

how about this

string GetContentAsRTF(RichTextBox rtb)
    var range = new TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd);

    using (var stream = new MemoryStream())
    using (var reader = new StreamReader(stream))
        range.Save(stream, DataFormats.Rtf);
        stream.Position = 0;
        return reader.ReadToEnd();

though the file type is RTF

commented: Not a VB code. +0
commented: That is not VB code. -3

Please post the code you are using to load and save the text. The usual way to load and save rich text is as follows:

Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
End Sub

Private Sub btnLoad_Click(sender As System.Object, e As System.EventArgs) Handles btnLoad.Click
End Sub
commented: Use this if you want to save/load from/on RichTextBox +0
Member Avatar

Thank you so much, Reverend Jim, I didn't know that RichTextBox has .Save and .Load features :-)
If you still need the code I was using...

               Dim objWriter As New System.IO.StreamWriter(FILE_NAME)

(I was using objWriter to write the text from the richtextbox)

I didn't know that RichTextBox has .Save and .Load features

Neither did I when I first started using it. That's why I like to browse the intellisense methods from time to time. If this gives you what you need then please mark this thread solved.

Just a bit of info to add to the discussion.

Your original code will give you your expected result if you change

Those dang computers always try to do what you tell them to do, not what you want them to do. :)

That said, its easier to use the Save and Load methods as Jim has shown you.

commented: Thanks. +0