Note that this code only saves the plain text contents of the RichTextBox control. If you want to save the formatted contents of the control (including font styles, colors, etc.), you'll need to use a different file format, such as RTF or HTML. To save the contents of the control in RTF format, you can use the following code:
xxxxxxxxxx
// Save the contents of the RichTextBox control to a text file in RTF format
richTextBox1.SaveFile("output.rtf", RichTextBoxStreamType.RichText);
save the contents of a RichTextBox control to a text file:
xxxxxxxxxx
// Save the contents of the RichTextBox control to a text file
using (StreamWriter writer = new StreamWriter("output.txt"))
{
writer.Write(richTextBox1.Text);
}
xxxxxxxxxx
// Save the contents of the RichTextBox control to a text file in HTML format
richTextBox1.SaveFile("output.html", RichTextBoxStreamType.Html);