Something that a lot of people note with the Path class is that it has a method called ‘GetInvalidPathChars’, but the list doesn’t return two key values which obviously, are not allowed to be used as part of file names: ‘*’ and ‘?’.
The reason is that this method is intended mostly to be used by people working with our other IO APIs, where we accept a searchstring (an example is Directory.GetFiles(string path, string pattern)). The searchstring allows you to use ‘*’ and ‘?’ as part of the searchpattern, supporting a rudimentary searching mechanism, much to what you might expect through the command-window. This allows you to write code like so:
// searchstring here is supposedly, from some user input box
bool searchStringIsInvalid searchString.IndexOfAny(Path.GetInvalidPathChars());
So the existing method actually has a specific intent a very good usage pattern. However, many people still want the list of invalidchars, but they also want that list to contain ‘*’ and ‘?’, so that they can determine if a filename or directoryname provided in an input box, is valid. The solution? Keep an eye out for the new method in Whidbey on Path called ‘GetInvalidFileNameChars’.
It’s often those small features that can help just polish up the solution.