private void btnDump_Click(object sender, EventArgs e)
{
using (StreamWriter sw = new StreamWriter("E:\\TestFile.txt"))
{
// Add some text to the file.
sw.WriteLine(txtChange.Text);
}
}
This dumps the text of txtChange to a text file. txtChange is a Rich text box and has line breaks (new lines) in it.
When the user clicks the Dump button all the text is Dumped but not on new lines.
E.g. txtChange looks like
1
2
3
4
dumping the text looks like 1234
How do i format the dumping of the text so that the text is on new lines?
You can also do:
You should use the
Lines
property instead:You don't really need to use a stream since the
File
class contains these static convenience methods - short and to the point.Above will replace any existing content with the text lines contained in your text box
txtChange
. If you want to append content use the appropriately namedFile.AppendAllLines()
instead.If it contains \r's as you mentioned, you should try this
just add a newline char:
Take a look at Replace Line Breaks in a String C# and replace all linebreaks so it matches Windows Standard.
take a look at http://en.wikipedia.org/wiki/Newline#Representations for linbreak definitions.