Home     Products      Support      Corporate     Sign In 
Support Knowledge Base, Article 375
Product
FileUp
Title
Can FileUp process an upload containing multiple files?
Solution

FileUp is capable of processing an upload containing multiple files, but it is important to understand the difference between the different Save methods. This article will explain the difference between calling Save methods on the FileUp object versus the File object, the impact this has on the number of files saved, as well as the proper use of the SaveRecursive method. The techniques that best demonstrate these differences are:

  • Saving only one file
  • Saving a file by referencing it explicitly
  • Iterating through the form element collection
  • Saving recursively

The behavior of the following Save methods of the FileUp object (Save, SaveAs, SaveAsBlob, SaveInVirtual) is to save one file. If multiple files are uploaded, only the first file will be saved.

Saving only one file:

'--- Instantiate the FileUp object
Set oFileUp = Server.CreateObject("SoftArtisans.FileUp")
 
'---Set the path property to control the location of the upload cache
oFileUp.Path = "c:\MyUploadFolder"
 
'---Calling the Save method of the FileUp object will only save one file.
oFileUp.Save
 
set oFileUp = Nothing

When these same methods are called from FileUp's File object, they can be called on each file individually, allowing all of the uploaded files to be saved. This can be done by referencing each file explicitly, or for greater flexibility, the files can be saved by iterating through the form element collection. This allows the files to be saved without knowing the names or number of file input controls from the submitting form.

Saving a file by referencing it explicitly:

'--- Instantiate the FileUp object
Set oFileUp = Server.CreateObject("SoftArtisans.FileUp")

'---Set the path property to control the location of the upload cache
oFileUp.Path = "c:\MyUploadFolder"
 
'---"myFile1" is the name of the file input control
'---on the submitting form.
'---Calling a Save method on an empty control
'---will generate an error.
 
If Not oFileUp.Form("myFile1").IsEmpty Then
  oFileUp.Form("myFile1").Save
End if
 
If Not oFileUp.Form("myFile2").IsEmpty Then
  oFileUp.Form("myFile2").Save
End if
 
Set oFileUp = Nothing

Iterating through the form element collection:

'--- Instantiate the FileUp object
Set oFileUp = Server.CreateObject("SoftArtisans.FileUp")

'---Set the path property to control the location of the upload cache
oFileUp.Path = "c:\MyUploadFolder"

For Each strFormElement In oFileUp.Form

  '--- If it's a file, IsObject() will return True
  '--- if it's a conventional form element, it will be false
  If IsObject(oFileUp.Form(strFormElement)) Then

    '--- It's a file element, so we'll see if it's empty or not
    If Not oFileUp.Form(strFormElement).IsEmpty Then

      '--- It's not empty, so we'll save it
      oFileUp.Form(strFormElement).Save

    End If

  '--- If it's not a file, it's a conventional text-based form element
  '--- Insert appropriate code for conventional form elements here.
  End If
Next

Set oFileUp = Nothing

FileUp has an additional Save method for processing recursively uploaded directories. Uploading recursively requires the use of Xfile or Jfile as the client application to generate the upload request. Uploading a directory recursively means that the directory and its contents, including its subdirectories will be automatically included in the upload. FileUp will then save this directory with the structure of the subdirectories and files preserved. In this situation, FileUp's SaveRecursive method should be used. SaveRecursive is a method of the FileUp object and only needs to be called once. It will save all of the files in the upload.

Saving Recursively: (assumes Xfile or JFile as client)

'--- Instantiate the FileUp object
Set oFileUp = Server.CreateObject("SoftArtisans.FileUp")
 
'---Set the path property to control the location of the upload cache
oFileUp.Path = "c:\MyUploadFolder"
 
'--- Call SaveRecursive if uploading recursively
oFileUp.SaveRecursive
 
Set oFileUp = Nothing
Created : 6/26/2003 2:59:50 PM (last modified : 2/22/2007 6:16:23 PM)
Rate this article!
Comments