I need to write a strings into a text file from C#, each string on a new line...How can I do this?
You can use File.WriteAllLines:
string[] mystrings = new string[] { "Foo", "Bar", "Baz", "Qux" };
System.IO.File.WriteAllLines("myfile.txt", mystrings);
If you wish to append the text lines to the file, use AppendAllText:
string appendText = "This is extra text" + Environment.NewLine;
File.AppendAllText(path, appendText);
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