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:
and so on.

Open in new window

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).
Éric MoreauSenior .Net ConsultantCommented:
net_susanAuthor Commented:
I'm going to try this, but I'd like to do it on the client side if possible.
net_susanAuthor Commented:
I guess I'm just not figuring out how to plug this into what I have.
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).
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.