Is there an easy way to test a directory name for invalid characters before
trying to create that directory? I know how to get a character array of
invalid characters (Path.GetInvalidPathChars) but do I have to go to all of
the trouble of writing of my validation method or is there something built
in to the .NET Framework that I haven't found yet?

Re: Testing for invalid characters when creating a directory? by Carl

Carl
Sat Jul 29 14:31:18 CDT 2006

Dave wrote:
> Is there an easy way to test a directory name for invalid characters
> before trying to create that directory? I know how to get a
> character array of invalid characters (Path.GetInvalidPathChars) but
> do I have to go to all of the trouble of writing of my validation
> method or is there something built in to the .NET Framework that I
> haven't found yet?

string path = "....";
if (path.IndexOfAny(Path.GetInvalidPathChars()) >= 0)
{
// path contains invalid characters
}

-cd



Re: Testing for invalid characters when creating a directory? by Dave

Dave
Sat Jul 29 14:46:51 CDT 2006

Thanks. Originally I was thinking that I wanted a method to eliminate
invalid characters from the path string (the string was actually the name of
something else unrelated to a path) but now I think I'll just prohibit those
characters from the original string.


"Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@mvps.org.nospam>
wrote in message news:ulo0RW0sGHA.3264@TK2MSFTNGP03.phx.gbl...
> Dave wrote:
>> Is there an easy way to test a directory name for invalid characters
>> before trying to create that directory? I know how to get a
>> character array of invalid characters (Path.GetInvalidPathChars) but
>> do I have to go to all of the trouble of writing of my validation
>> method or is there something built in to the .NET Framework that I
>> haven't found yet?
>
> string path = "....";
> if (path.IndexOfAny(Path.GetInvalidPathChars()) >= 0)
> {
> // path contains invalid characters
> }
>
> -cd
>
>