Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Appending text to a file with Newline in C#

You can append text to a file with newline using Environment.Newline.

  1. using System;
  2. using System.IO;
  3.  
  4. namespace forgetCode
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. Console.WriteLine("Please enter the content to append in to the file - type exit and press enter to finish editing:");
  11. string newContent = Console.ReadLine();
  12. while (newContent != "exit")
  13. {
  14. File.AppendAllText("D:\\test.txt", newContent + Environment.NewLine);
  15. newContent = Console.ReadLine();
  16. }
  17.  
  18. }
  19. }
  20. }


Output:
The text will be written to the file with newline inserted in the mentioned path.


..