:: KBs ::

Reading a Text File

Created Date: 4/23/2008
Last Modified Date: 4/23/2008
One of the most interesting pieces within the .Net runtime is no simplistic support for opening a text file. Unlike items like XML, which has a Load method, text files have no intrinsic way of handling this.

Here is some sample code that actually performs an open file.

C#
using System.IO;

protected internal static String OpenFile(String FileName)
{
String ReturnString;
using (StreamReader reader = File.OpenText(FileName))
{
ReturnString = reader.ReadToEnd();
}

return ReturnString;
}
:: Coding Basics ::