Latest post

Read text file

This reads the text file and returns null if file does not exist.




public static string ReadTextFile(string path)
{
 if (System.IO.File.Exists(@path))
 {
  var text = System.IO.File.ReadAllText(@path);
  if (!string.IsNullOrEmpty(text))
  {
   return text;
  }    
 }

 return null;
}

Usage:

string filePath = @"C:\temp\data.txt";
var stringData = ReadTextFile(filePath); 



Comments

Popular posts from this blog

Entity Framework Core Custom Pluralizer - .Net Core