top of page

How to Read a Text File in C#

public static string readTextFile(string sFiletoread)

{

string sRetText = "";

try

{

using (StreamReader sr = new StreamReader(sFiletoread))

{

sRetText = sr.ReadToEnd();

}

}

catch (Exception e)

{

Console.WriteLine(e.ToString()); sRetText = e.ToString();

}

return sRetText;

}

Please reload

  • facebook-square
  • Twitter Square
  • google-plus-square

© 2014 by Newel Software LLC.

bottom of page