当用户可以插入TextBox
时,我有简单的File path
。
现在我想验证此File path
是否有效,例如:
c:\blabla --> this valid
c: \blabla --> this Not valid
我有这个功能:
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;
}
但是这一直都会返回True
。
任何可以验证此问题的建议或准备c#
方法?