The following code reads a text file into a string object. It doesn’t get any simpler than this. In production code always make sure that you handle exceptions.
using System.IO;
....
// filePath should contain the complete path to a file.
StreamReader stream = new StreamReader(filePath);
fileText = stream.ReadToEnd();
stream.Close();
Share with