Persits Software, Inc. Knowledge Base Articles

HOWTO: Determining whether a file was selected for uploading

Problem Description

If a form contains multiple items <INPUT TYPE="FILE">, it is often necessary to check whether a particular item has been used to select a file or left blank by a user.


To check at run time whether a particular form item was used to select a file, the following syntax may be used:

Set File = Upload.Files("FILE1")
If File Is Nothing Then
  Response.Write "file not selected."
  Response.Write File.Path
End If

It is possible for the user to type a name of a file that does not exist into the file-selection text box. If this occurs, the file will be added to the Upload.Files collection and no error will be detected. The way to catch this case is to check whether the size of an uploaded file is 0.

If File.Size = 0 Then
  Response.Write "Invalid file uploaded."
End If