Possible Duplicate:
How check if given string is legal (allowed) file name under Windows?
I am new to stackoverflow. I know its a silly question, but I am stuck in it. I want to validate a filename so that it should only accept legal path. I have tried the below code:
if (txtFileName.IndexOfAny(System.IO.Path.GetInvalidFileNameChars()) != -1)
{
MessageBox.Show("The filename is invalid");
return;
}
It worked, however, I was a bit confused whether it will fully work or not so I wanted to know other answers too. I think we can also validate a filename using Regular Expression too. Any help will be great.