Search Persits Software Knowledge Base

 

Article PS01060656

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.

Solution

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."
Else
  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

Created: 2/8/2002 5:17:13 AM
Last Modified: 12/12/2003 5:47:12 PM

Copyright © Persits Software, Inc. 1998 - 2018
For technical support, write to support@persits.com.