Introducing Radical.sh

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

Reading from a file using ReadAllText() in C#

We can use File.ReadAllText(Filepath) for reading the content of a file.
This is the example:
  1. using System;
  2. using System.IO;
  3.  
  4. namespace forgetCode
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. string path = "D:\\test.txt";
  11. if (File.Exists(path))
  12. {
  13. string content = File.ReadAllText(path);
  14. Console.WriteLine("Current content of file:");
  15. Console.WriteLine(content);
  16. }
  17.  
  18. }
  19. }
  20. }


Output:
The content will be shown here from D:\\test.txt

..