GetNextFile (Dundas Upload Control 2.0)

Dundas

GetNextFile (Dundas Upload Control 2.0)

Overview | Properties | Methods

Call this method to retrieve the headers for uploaded files one at a time.

Syntax

Set NextFileObject = UploadObject.GetNextFile()

Remarks

This method reads an HTML form in a top-down manner and returns a NextFile object when data from a populated file input box is encountered. Any form data (e.g. textbox data) prior to the populated file input box is uploaded to the Form collection. "Nothing" is returned if no populated file input box is found.

Please note that if the user did not specify any files to be uploaded then calling this method for the first time will result in the Upload control's Form collection to be populated with ALL values entered by the user into the form's elements.

To loop through all uploaded files use a "Do Until" loop, and test to see if the returned NextFile object is "Nothing". See the sample code below for an example of this.

Only the header for the file is uploaded, and you can programmatically decide if you want to retrieve the file in its entirety, depending on some sort of criteria (e.g. if the file is an image). If you want to retrieve the entire file then call either the Save method or the SaveToMemory method of the NextFile object BEFORE calling GetNextFile again. If you call GetNextFile again WITHOUT calling Save or SaveToMemory then the file in question will NOT be uploaded.

If you call Save or SaveToMemory then the uploaded file will also have a corresponding UploadedFile object appended to the control's Files collection.

The advantage of this method is that you are not forced to retrieve all form data at once. The ability to accept or reject uploads is also advantageous to the developer.

See Also: NextFile Object | Tutorial 2: Retrieving Form Data Incrementally Using the GetNextFile Method

Example

'Note: it is assumed that a form (which contains one or more file input boxes) is posting data to this page with an encoding type of "multipart/form-data"

'create an instance of the Upload control Set objUpload = Server.CreateObject("Dundas.Upload.2")

'retrieve the header for the first uploaded file
Set
objNextFile = objUpload.GetNextFile()

Do Until objNextFile Is Nothing
'loop through all uploaded files and retrieve the uploaded file if it is an image

If InStr(1,objNextFile.contenttype,"Image",1) Then

objNextFile.SaveToMemory()

End If

'retrieve header for next uploaded file
Set
objNextFile = objUpload.GetNextFile()

Loop

'destroy object
Set
Upload = Nothing