Click to See Complete Forum and Search --> : Save txt and img to one file using an rtf box


firedraken
January 18th, 2008, 01:47 AM
I am trying to save a file that has an image pasted in along with the text that is typed. I have been able to get the text to save with no problem but the image pasted in is not saving.

here is the code I am using:

string path1 = cmbCat.Text;
FileStream fs = new FileStream("\\BOS\\Cat\\" + path1 + "\\" + textBox1.Text + ".wri", FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite);

StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Default);
sw.Write(txtBox1.Text);
sw.Flush();
sw.Close();
fs.Close();

it saves the text just find but does not save the image. What can i do and how?

MMH
January 18th, 2008, 01:57 AM
Does *.wri format supports image ? :confused:

jmcilhinney
January 18th, 2008, 02:20 AM
Of course it saves only the text. That's what a StreamWriter is for: to write text. Look at this:sw.Write(txtBox1.Text);You're specifically writing the text. If you want to save an image then you have to save to a format that supports images. The RichTextBox is named as it is because is supports Rich Text Format. If you want to save all the formatting, images, etc. in the RichTextBox then you need to save the RTF code it contains. RTF code is somewhat like HTML code, and a RichTextBox is somewhat like a Web browser. It takes the code and renders it to a formatted output.

I suggest that you read the MSDN documentation for the RichTextBox control so you understand how it works. In doing so you'll encounter its SaveFile and LoadFile methods, which allow you to save and load files in one line of code to either plain text or RTF format.