Click here to Skip to main content
15,790,807 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hai friends,
Am having a richtextbox,and i have to convert that output,ie,some text into byte array using c# can i do this...
please help me...
Updated 18-Oct-19 15:03pm

The RichtextBox[^] has a Rtf property holding text and format directives. It is a string property.
You could convert it to byte array this way:
string rtf = myRichtextBox.Rtf;
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(rtf);

Here I used UTF8 encoding, but that choice is up to you.

Hope this helps.

EDIT: Later, if you want to recover original string from byte array, it can be done this way:
string originalRtf = System.Text.Encoding.UTF8.GetString(bytes);

You have to use the same Encoding in both operations.
Share this answer
Helen Paulose 30-Apr-14 5:31am    
Hai,Philo,string rtf = myRichtextBox.Rtf; this doesnt work in my system.
phil.o 30-Apr-14 5:40am    
Of course, you replaced "myRichtextBox" with the name of your actual control, didn't you?
Helen Paulose 2-May-14 4:36am    
yah,i had changed
phil.o 2-May-14 4:53am    
What is the real error message?
I see your problem. I don't think you are using .rtf format. Do

string rtf = richTextBox1.Text

That should work. Replace
with the name of YOUR control)
Share this answer
Dave Kreskowiak 18-Oct-19 21:22pm    
I seriously doubt the OP is still trying to solve this 5 years later.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900