detecting empty 'input type=file' fields?

  • Thread starter Thread starter darrel
  • Start date Start date
D

darrel

I have some INPUT TYPE=FILE fields on a page. There are four of them and I'd
like to validate them. They can either be empty, or need a certain filename.

This is what I am doing:

if (fileUpload_instDOC.PostedFile.FileName.length = 0 OR
lcase(right(fileUpload_instDOC.PostedFile.FileName, 3)) = "doc")
I'm checking to see if it is a word document, or empty.

The problem is the empty part. I can't get that to work. It seems to be
ignoring that completely.

-Darrel
 
Try using fileUpload_instDoc.PostedFile.ContentLength

you should also use OrElse instead of just Or, since it's short-circuited
resulting is faster (by nanoseconds) code and (more importantly) more
readable..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
 
Hi Darrel,

Here's a tip regarding File Upload elements: Validate on the client. Why?
Because the file size may be quite large for all you know, and if you upload
it before validation, the entire file will be uploaded before it is
verified. If it is not verified, the correct file will then have to be
uploaded. This will cause a performance drag on the client (read "slow
things down").

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
Here's a tip regarding File Upload elements: Validate on the client.

Well, this is actually set for client-side validation. It's a good tip,
though.

-Darrel
 
The problem is the empty part. I can't get that to work. It seems to be
ignoring that completely.

I'm an idiot. This was a user error issue. Thanks for the help, Karl and
Kevin!

-Darrel
 

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

Back
Top