Code To Read Text File

Posted by Lakhangarg under ASP.NET category on | Views : 2112
With this code we can read the content of .txt File.

Suppose we have a txt file name test.txt on c:\ driver and we want to read the contents of this file.

string textFileContents = string.Empty;;
string filePath = @"C:\test.txt";
StreamReader re = File.OpenText(filePath);
textFileContents = re.ReadToEnd();

Now in the above code textFileContents string contains the content of test.txt file

Thanks & Regards
Lakhan Pal Garg

Comments or Responses

Login to post response