473,385 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to validate a file name in vb.net?

I have a simple textbox. I want to make sure that the string typed in by a user is a
valid windows filename.
Can anyone point me to some classes that will help? Ideally, I guess I should create my
own textbox class that only allows the typing of a valid filename. Perhaps checking
against a regex on keypress?

Any help would be appreciated.

Thank you in advance.
Nov 21 '05 #1
5 11951
"Darious Snell" <nu**@sdlkfweu.org> schrieb:
have a simple textbox. I want to make sure that the string typed in by a
user is a
valid windows filename.
Can anyone point me to some classes that will help? Ideally, I guess I
should create my
own textbox class that only allows the typing of a valid filename.
Perhaps checking
against a regex on keypress?


I doubt that you will come up with a stable solution. There are many
factors which influence whether or not a filename is valid. For example,
the user's privileges can be insufficient to access, modify, or create the
file, etc. Maybe using the OpenFileDialog component is an option.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2
Make sure it doesn't contain Path.InvalidPathChars or isn't = "".
"Darious Snell" <nu**@sdlkfweu.org> wrote in message
news:11*************@corp.supernews.com...
I have a simple textbox. I want to make sure that the string typed in by a
user is a
valid windows filename.
Can anyone point me to some classes that will help? Ideally, I guess I
should create my
own textbox class that only allows the typing of a valid filename.
Perhaps checking
against a regex on keypress?

Any help would be appreciated.

Thank you in advance.

Nov 21 '05 #3
A really low tech way:
1) Check to see if the file exists. If it does, you have your answer.
2) If it doesn't exist, create the file. If it works, close and kill it,
you have your answer.
3) If it can't be created, you have your answer.

Bobbo
Nov 21 '05 #4
Hi Robert ! :O)
3) If it can't be created, you have your answer.


hmm... i'm not sure it's reliable.
There can be a whole lot of reasons for a file creation to fail. Look up the
Exception's types that can be thrown by the File.Create() method...

--
Best Regards
Yanick
Nov 21 '05 #5
Here is a link to a regular expression which validates file names.
Perhaps this will help you:

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

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: JonChart | last post by:
Hi all, I would like to know ho to validate a file name when uploading via asp and whether or not this can be validated with javascript? I need to upload 2 images and the file names must be...
6
by: Allen | last post by:
Hi, I want to retrieve the selected folder and entered file name from the SaveFilsDialog. The user is able to create or selected a different folder during the dialog displayed. If user enters...
1
by: Gaetan | last post by:
I have a web application where the user can type the name of a file name in a field. I want to make sure the syntax of that filename is valid before using it. I browsed the methods in various...
3
by: sheeeng | last post by:
Hi all, I know that we can check for invalid file name characters as shown at http://www.codeproject.com/useritems/reallyusefulpath.asp. But how can we check a string for invalid file name...
9
by: Sam | last post by:
Validate domain name context Hello , Today I want to make sure from a given text is a domain style or not. for example : the domain can be example.com or example.com.us or example.us so ,...
2
by: harry | last post by:
I need to validate a file name but it has to work on Windows & Unix! Does anybody know of java code that does this? thanks in advance harry
4
by: carmelo | last post by:
Hi! I need to read and store data from a file, but I don't the name of it; Is this code correct and is there a better way to do this thing?? int main() { cout << " type file name:" char *...
185
by: jacob navia | last post by:
Hi We are rewriting the libc for the 64 bit version of lcc-win and we have added a new field in the FILE structure: char *FileName; fopen() will save the file name and an accessor function will...
3
by: laredotornado | last post by:
Hi, Can anyone provide a function that can validate if a string would pass as a valid Unix (specifically Fedora Core 8 Linux) file name? For example, I'm fairly certain one of the rules is that...
2
by: lenniekuah | last post by:
Hullo Good Guys, I have an intesting problem and I need your help. Please help me. I am using Vb.NET2008 to develop Window Application. When the user enter the File Name on the textbox, I need to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.