The Output of this code
string fileDateTime = "StepsGA-" + DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss") + ".txt";
string fname = System.IO.Path.Combine(System.Environment.CurrentDirectory, fileDateTime);
File.WriteAllText(fname, txtSteps.Text);
doesn't preserve newline as it should be. All the contents of the textbox are printed in a horizontal long line ! Where have I gone wrong? Thanks !
WriteAllText (String, String) Creates a new file, writes the specified string to the file, and then closes the file. If the target file already exists, it is overwritten.
Preserve Newlines, Line Breaks, and Whitespace in HTML Use the white-space: pre; setting to display long-form content containing whitespace and line breaks the same way as provided by a user. The text will also stay inside the container boundaries and now overflow the parent: <span style="white-space: pre;"> This is a long-form text.
The default behavior of the WriteAllLines (String, IEnumerable<String>) method is to write out data by using UTF-8 encoding without a byte order mark (BOM).
Preserve Newlines, Line Breaks, and Whitespace in HTML Sometimes you want to display the content in the same format as typed in a textarea. For example, a text from a textarea may contain line breaks or empty lines. The white-space CSS property is helpful displaying the text in the same way it’s provided by the user.
Got the answer ! Instead of \n
I needed to use Environment.NewLine
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With