[VB.NET] Check a right filename...

T

tranky

HI....
In my vb.net project the user can insert into an imputbox a filename.
In what manner i can check the filename, so that will be accepted in a
Windows System? (i want that inside of the filename there isn't ";" , "*" ,
and all the charachters that windows doesn't accept...).I think is a bad
idea to use the Instr function for all that charachters.

I hope in your ideas.
from italy thank you.
 
K

Ken Tucker [MVP]

Hi,

You could use a regular expression for that. This example requires
the path so c:\test.txt will work but test.txt will not. Take a look at
regexlib.com for more examples.

Dim regFileName As New System.Text.RegularExpressions.Regex( _
"^([a-zA-Z]\:)(\\[^\\/:*?<>""|]*(?<![ ]))*(\.[a-zA-Z]{2,6})$")
Dim strOut As String = IIf(regFileName.IsMatch(TextBox1.Text), "Valid",
"Invalid").ToString
MessageBox.Show(strOut)

http://www.regexlib.com/REDetails.aspx?regexp_id=357


Ken
-----------------------
HI....
In my vb.net project the user can insert into an imputbox a filename.
In what manner i can check the filename, so that will be accepted in a
Windows System? (i want that inside of the filename there isn't ";" , "*" ,
and all the charachters that windows doesn't accept...).I think is a bad
idea to use the Instr function for all that charachters.

I hope in your ideas.
from italy thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top