read file to string c# code example
Example 1: read text file to string c#
string mystring = System.IO.File.ReadAllText(@"C:\Users\Public\TestFolder\WriteText.txt");
Example 2: c sharp how to read a text file
string text = System.IO.File.ReadAllText(@"C:\filepath\file.txt");
string[] lines = System.IO.File.ReadAllLines(@"C:\filepath\file.txt");
Example 3: c# read all text from a file
using (StreamReader streamReader = new StreamReader(path_name, Encoding.UTF8))
{
contents = streamReader.ReadToEnd();
}
Example 4: c# read file into a string
string mystring = File.ReadAllText(your_file_location, Encoding.UTF8);