On Windows-based desktop platforms, invalid path characters might include quote ("), less than (<), greater than (>), pipe (|), backspace (\b), null (\0), and Unicode characters 16 through 18 and 20 through 25.
We can use the code blow:
*******************************************************
using System.Text;
using System.Text.RegularExpressions;
public bool IsFilenameValid(string fileName)
{
Match m = Regex.Match(fileName, @"[\\\/\:\*\?\" + Convert.ToChar(34) + @"\<\>\|]");
return !(m.Success);
}
*******************************************************
Or in .NET 1.1
We can use "fileName.IndexOfAny(System.IO.Path.InvalidPathChars)" to validate filename.
No comments:
Post a Comment