The System.IO.Path.InvalidPathChars doesn't include * and ?, which are valid in a path (e.g. "dir t*" or dir "t?p"). They aren't valid when creating a new file or directory, and will cause an exception if you try to use them.
The original IsFilenameValid using the Regex function is more useful if you are validating a filename that the user has input (such as when creating a file).
.Net 2 provides the Path.GetInvalidFileNameChars method that can be used instead of the System.IO.Path.InvalidPathChars property to make a method similar to that suggested by bobbyrward.
Bobby R Ward
---------------------
bobbyrward@gmail.com
public bool IsFilenameValid(string inputFileName)
{
return inputFileName.IndexOfAny(System.IO.Path.InvalidPathChars);
}
The original IsFilenameValid using the Regex function is more useful if you are validating a filename that the user has input (such as when creating a file).
.Net 2 provides the Path.GetInvalidFileNameChars method that can be used instead of the System.IO.Path.InvalidPathChars property to make a method similar to that suggested by bobbyrward.