|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Testing for invalid characters when creating a directory?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? Dave wrote:
> Is there an easy way to test a directory name for invalid characters string path = "....";> 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? if (path.IndexOfAny(Path.GetInvalidPathChars()) >= 0) { // path contains invalid characters } -cd 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. Show quote "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 > > |
|||||||||||||||||||||||