saving rich text box data!

L

Lee

Hi,

I have a rich text box that can have hyperlinks ect within the text!

when I save this data to file how should I do it? that is can I just save it
as text?

or do I need to serialize it beforehand to preserve the hyperlink info?

thanks in advance
 
L

Lars-Inge Tønnessen \(VJ# MVP\)

when I save this data to file how should I do it? that is can I just save
it as text?


If your rich text box is called "richTextBox1", you can load a file like
this:

this.richTextBox1.LoadFile("C:\\Document.rtf");

and save the content with this line:

this.richTextBox1.SaveFile("C:\\newFile.rtf");

Regards,
Lars-Inge Tønnessen
 
L

Lee

sorry I wasn't very clear,

I am saving the rich text box data as part of an xml file.

thanks
 
L

Lars-Inge Tønnessen \(VJ# MVP\)

You get the raw rtf from the "Rtf" method (this.richTextBox1.Rtf).
You would have to code this rtf formatted text into characters that XML can
store. XML can not store all charaters.

Format the rtf as Base64.

this.richTextBox1.LoadFile("C:\\Document.rtf");
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
string StoreMe =
System.Convert.ToBase64String(enc.GetBytes(this.richTextBox1.Rtf));
System.Windows.Forms.MessageBox.Show(StoreMe);

Regards,
Lars-Inge Tønnessen
 
L

Lars-Inge Tønnessen \(VJ# MVP\)

how on earth do I read the Base64 data back into a string?

Like this:

this.richTextBox1.LoadFile("C:\\Document.rtf");

// From RTF to Base64
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
string StoreMe =
System.Convert.ToBase64String(enc.GetBytes(this.richTextBox1.Rtf));
System.Windows.Forms.MessageBox.Show(StoreMe);

// Back from Base64 to RTF
byte[] result = System.Convert.FromBase64String(StoreMe);
string RTFString = enc.GetString(result);
System.Windows.Forms.MessageBox.Show(RTFString);


Regards,
Lars-Inge Tønnessen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top