Reading from a file using the System.IO.File class
suggest changeYou 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");
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents