0

I have simple TextBox when the user can insert File path.

Now I want to validate if this File path is valid for example:

c:\blabla --> this valid

c:  \blabla --> this Not valid

I have this function:

public static bool ValidateFilePath(string path)
{
    FileInfo fileInfo = null;
    try
    {
        fileInfo = new FileInfo(path);
    }

    catch (ArgumentException) { }
    catch (PathTooLongException) { }
    catch (NotSupportedException) { }
    if (fileInfo is null)
        return false;
    else
        return true;
}

But this return True all the time.

Any suggestion or maybe ready c# method that can verify this ?

Dean Movy
  • 139
  • 1
  • 9
  • [`File.Exists(path)`](https://msdn.microsoft.com/en-us/library/system.io.file.exists(v=vs.110).aspx) – Ron Beyer Mar 16 '18 at 18:34
  • I mention that i want to check if file is Valid file path not exist, this file should create but i want to verify that the path is valid\ – Dean Movy Mar 16 '18 at 18:35
  • You'd likely have to Regex to make sure the path has the proper syntax for a file path. – Him_Jalpert Mar 16 '18 at 18:38

0 Answers0