Reputation: 1122
I'm trying to save the text from my RichTextBox to a text file. However, upon doing so, the new lines in the RTB aren't considered "new lines" and hence a \n
isn't appended in the text file, so if I have:
This is a test
line of content
It will write to the text file as:
This is a testline of content
I'm saving the text the following way:
File.WriteAllText(currentFile, richTextBox1.Text);
I'm just wondering if there's any solution for this. Thanks.
Upvotes: 0
Views: 80
Reputation: 9726
Use the built it SaveFile
method instead.
richTextBox1.SaveFile(currentFile, RichTextBoxStreamType.PlainText);
Upvotes: 1
Reputation: 449
Try this:
StreamWriter sw = File.CreateText(currentFile);
for (int i = 0; i < richTextBox1.Lines.Length; i++)
{
sw.WriteLine(richTextBox1.Lines[i]);
}
sw.Flush();
sw.Close();
or use the rtb.SaveFile() method: http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.savefile%28VS.71%29.aspx
Upvotes: 1