Code To Read Text File

Lakhangarg
Posted by Lakhangarg under ASP.NET category on | Views : 2146
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.

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

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