C# Language Reading from a file using the System.IO.File class


Example

You can use the System.IO.File.ReadAllText function to read the entire contents of a file into a string.

string text = System.IO.File.ReadAllText(@"C:\MyFolder\MyTextFile.txt");

You can also read a file as an array of lines using the System.IO.File.ReadAllLines function:

string[] lines = System.IO.File.ReadAllLines(@"C:\MyFolder\MyTextFile.txt");