A File-Uploading Windows Script Component, Part 2
By Andy Smith
In Part 1 we briefly discussed the three objects for
our Windows Script Component and looked at the FileUp object in detail. In this
part we'll examine the Form and UploadControl objects in the same
detail!
The Form Object
The major function with the Form object is the Build method. This
method is called automatically, so you don't have to worry about it, but it decides if it
really needs to parse the Post, and does so. The function that does the parsing is
BuildUploadRequest, and is a Private function.
This function, originally written by Philippe Collignon (author of File Uploading with ASP and VBScript),
was heavily modified by me to allow for a more object-oriented, robust solution. The internal
data representation is still a Dictionary object, though it is now filled with
UploadControl objects instead of more Dictionary objects. I won't get into how
it parses the Post, that can be better stated in his article.
Probably the only two Properties you'll use in your pages are Item and Items.
Item takes either an UploadControl's Name or Index and attempts to return it.
Here's how it's implemented:
|
Items is necessary because, as far as anyone I've asked can tell, ( and this
includes people with access to the VBScript source code ) it's impossible to implement the
For Each ... Next construct within VBScript. So the Items property
steals this interface from the Dictionary object that stores the parsed request. You would
use it in your code like this:
|
The UploadControl
It has a whole bunch of properties, most of which you'll only use on Files. The default
property, Item, returns the value of normal controls, and the filename of File
controls. Value returns either a string or the binary data of a file. There is also,
FileName, Extension, Path, ContentType,
SavePath, and OverWrite for files, as well as Save and
SaveAs methods for the File controls. The only ones that are really interesting
are the Save and SaveAs methods. They use a FileSystemObject to
save the file to the harddisk by Looping through the Binary Data one character at a time, and
writing it, like such:
|
Note that if you don't set the SavePath on either this UploadControl
or on the FileUp object, it will save the file to the folder that the script is
running in.
Some examples of using the UploadControl properties:
|
That's all there is to it! The code for the component and an example ASP page is included. Have fun, and happy programming!
Attachments:




