I have here a textbox that should accept a file path. How should I validate (by a button click) whether the given path file do exists or not?
For example, “C:MyDocs\sample.txt” should be invalid because it is not actually existing in my local drive and there’s no ‘\’ after ‘C:’..
i have tried using this:
FileInfo fi = new FileInfo(fName);
if (fi.Exists)
//do something
but it doesn’t satisfy my issue..can anyone advise?
use
Uri.IsWellFormedUriString(path, UriKind.Absolute);to check if the path is valid (beside if the file exists)read here for Uri validation:
http://msdn.microsoft.com/en-us/library/system.uri.iswellformeduristring.aspx
Sample:
if the result is true, you can know for sure that the file format supplied by the user is valid and the file exists @ the file system.