473,396 Members | 1,886 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,396 software developers and data experts.

detecting empty 'input type=file' fields?

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
Nov 19 '05 #1
4 2793
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!)
"darrel" <no*****@hotmail.com> wrote in message
news:ed**************@TK2MSFTNGP09.phx.gbl...
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

Nov 19 '05 #2
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.

"darrel" <no*****@hotmail.com> wrote in message
news:ed**************@TK2MSFTNGP09.phx.gbl...
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

Nov 19 '05 #3
> 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
Nov 19 '05 #4
> 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

Nov 19 '05 #5

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

Similar topics

1
by: balzano_1 | last post by:
Hi, im trying to upload a file from a client (windows) to an ftp server (linux), i deciede to use some of php`s functions to connect and authenticate etc.. i only wish to put a file on the server,...
1
by: Kristian | last post by:
The script below uploads the selected file and creates it on the server in the right directory and all looks fine. But the file is empty, it contains nothing... HTML FORM: <form name="foo"...
0
by: gotcha | last post by:
I have a little code to add multiple items to a shopping cart based page. This code works perfect, but it adds all of the info to the same input fields every time it loops. I need it to change...
15
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update...
2
by: ssriram | last post by:
Is there a way to apply style to form field input type="file" (file upload component) If so, how? Thanks, Sunitha Sriram -- ssriram
12
by: Larry Bud | last post by:
I rarely crosspost, but this affects both ASP and Javascript REALLY odd bug that I ran across in ASP 3.0. I have an input type of file, user clicks browse, then places his cursor in the...
13
by: elsheh | last post by:
Hi.. guys I’m trying to use JavaScript to validate my HTML for empty fields. My code is as below. The problem is that I can escape validation and submit empty fields. Any clue? <html> ...
10
meenakshia
by: meenakshia | last post by:
hi forum:) i have a form in which i have four input fields for pieces to be entered and 4 fields for amount what i want is that the first pieces-t1 should be visible and rest three should not show...
8
omerbutt
by: omerbutt | last post by:
hi there i have a form with multiple input (type/text ) fields and three inputs(type/file) fields i have to submit the form via ajax because i have multiple forms on this page ,you can say it is a...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.