Nice answer.  Thanks.

On Feb 15, 4:21 am, Cerebrus <[email protected]> wrote:
> Filenames may be valid on one OS and invalid on another. Since you
> haven't mentioned the OS, I'm assuming Windows. (In any case, we're
> talking about a .NET solution)
>
> Couple of options come to mind:
>
> 1. Create a FileInfo object passing in the test string and catch all
> possible exceptions. If it is a valid path, no exception will be
> raised. A point that many do not realize at first is that the file
> does not actually need to exist for a FileInfo object to be created
> with the path.
> 2. Check if the string contains any of the chars returned by the
> Path.GetInvalidPathChars() and Path.GetInvalidFileNameChars() methods.
> If it does, you have an invalid path.
>
> If you need to check for File existence, just call FileInfo.Exists().
>
> Check this page for more information on what constitutes a valid file
> name in Windows:http://msdn.microsoft.com/en-us/library/aa365247.aspx
>
> On Feb 15, 2:21 am, okey <[email protected]> wrote:
>
> > Apart from a regx, is there a method that will report if string is a
> > valid filename?

Reply via email to