How to determine no special characters are in filename

I have a .NET form that allows users to upload their text files. I don't want to allow files containing any special characters to be uploaded.

I only want characters.doc
or characters.docx
and so on.
<input id="DocFile" type="file" runat="server" title="upldFileBox" />
This is what is seen if I try to use a regular expression validator:
C:\Documents and Settings\syount\Desktop\test.docx
C:\Documents and Settings\syount\Desktop\test.doc
C:\Documents and Settings\syount\Desktop\test.txt
and so on.
 
string filename = Path.GetFileName(DocFile.Value);
But this is what is seen in the code behind:
text.doc
test.docx
and so on.

Open in new window

LVL 1
net_susanAsked:
Who is Participating?
 
net_susanConnect With a Mentor Author Commented:
I couldn't get enough help with the answer I was looking for, so I just made forced something else to be the filename (eliminating special characters).
0
 
Éric MoreauSenior .Net ConsultantCommented:
0
 
net_susanAuthor Commented:
I'm going to try this, but I'd like to do it on the client side if possible.
0
 
net_susanAuthor Commented:
I guess I'm just not figuring out how to plug this into what I have.
0
 
net_susanAuthor Commented:
I just want to look at the string filename and determine if there are any special characters in it (besides the one . before the extension name).
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.