IsEmpty Property

Object: SoftArtisans.SAFile
Syntax: IsEmpty
Type: Boolean
Read/Write: Read Only
Description:

This property indicates whether the user specified a valid file to upload.

When a user fills out a form containing a file (<input type="file" />), there are three possibilities:

  1. The user specifies a valid filename on the local PC.
  2. The user leaves the filename field blank, decides not to transmit a file, but presses the submit button anyway.
  3. The user specifies a filename that is either invalid or indicates a file that is unreadable.

In the second and third cases, the browser does not report an error. The browser simply proceeds with the upload but leaves the file contents of the upload empty.

Your recourse is to let the user perform the upload and test the IsEmpty property.

If the property is True, the user did not transmit a valid file.

If the property is False, the user did transmit a valid file.

See also the IsEmpty property for the SAFileUp object.

Examples:
ASP <%
'--- If the file does not exist, FileUp will
'--- throw an error when Save() is called.
If IsObject(fileUpload.Form("MyFile")) Then
If Not fileUpload.Form("MyFile").IsEmpty Then
fileUpload.Form("MyFile").Save
Else
Response.Write "There was no file submitted in the " & _          "form field."
End If
Else
Response.Write "The referenced field does not exist " & _
"or is not of type=""file"""
End If
%>
C# //--- Get a reference to the uploaded file field
SaFile file = (SaFile)fileUpload.Form["MyFile"];

//--- If the file does not exist, FileUp will
//--- throw an error when Save() is called.
if (file != null)
{
if (!file.IsEmpty)
{
file.Save();
}
}
VB.NET '--- Get a reference to the uploaded file field.
Dim file As SaFile = CType(fileUpload.Form("MyFile"), SaFile)

'--- If the file does not exist, FileUp will
'--- throw an error when Save() is called.

If Not (file Is Nothing) Then
If Not (file.IsEmpty) Then
file.Save()
End If
End If

Copyright © 2010 SoftArtisans, Inc. All rights reserved.