I am getting this error.
File not found.
StreamReader sreader = new StreamReader(@"c:\text.txt");
string strcontent = sreader.ReadToEnd();
How to check file available in the particular location.
I am getting this error.
File not found.
StreamReader sreader = new StreamReader(@"c:\text.txt");
string strcontent = sreader.ReadToEnd();
How to check file available in the particular location.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
SenthilkumarPosted Apr 19, 2012, 4:51 AM
You have to do file check whether file exists in the position or not.
Otherwise it will give the run time error.
The File class provides the method to check file exists or not in the given path.
you can do the check like the following.
Hope this will help you.
Sam HobbsPosted Apr 19, 2012, 9:09 PM
Are you sure you want "text" and not "test"? You might have a slight mis-spelling. If so then the technique I describe above would give you a really big clue.
Krishna GaradPosted Apr 19, 2012, 1:58 AM
if (File.Exists(@"c:\test.txt"))
{
//your stuff here
}