Determine via C# whether a string is a valid file path

You can use the FileInfo constructor. It will throw a ArgumentException if “The file name is empty, contains only white spaces, or contains invalid characters.” It can also throw SecurityException or UnauthorizedAccessException, which I think you can ignore if you’re only concerned about format.

Another option is to check against Path.GetInvalidPathChars directly. E.g.:

boolean possiblePath = pathString.IndexOfAny(Path.GetInvalidPathChars()) == -1;

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)