Un metodo per leggere il contenuto di un file di testo (fn) in C#

C#

private static string ReadFile(string fn)
{
  string s;
  try
  {
    StreamReader re = File.OpenText(fn);
    s = re.ReadToEnd();
    re.Close();
  }
  catch
  {
    MessageBox.Show("Can't read file.", "Error",
      MessageBoxButtons.OK,
      MessageBoxIcon.Error);
    s = "";
  }
  return s;
}
Tags:
C#235 Esempi224
Potrebbe interessarti anche: