ASPUPLOAD.DLL

Version 1.51

by

FreeVBCode.com

http://www.freevbcode.com

Disclaimer: The ASPUpload.dll component and all its code (the “package”) is provided “as-is” by FreeVbCode.com, which is not responsible for any real or perceived harm to computer systems or software with which it is used. You are free to modify the code and/or use the package yourself in any way you see fit. You are free to redistribute the package under the following conditions:

1) appropriate credit is given to FreeVBCode.com including a link to the site, 2) this documentation is provided unaltered and in full, and 3) you do not charge any kind of fee for the code or binary version of the class without the express permission of FreeVBCode.com. This permission does not include the right to upload the package to another web site. DO NOT, UNDER ANY CIRCUMSTANCES, POST (OR SUBMIT FOR POSTING) THIS PACKAGE TO ANOTHER WEB SITE WITHOUT THE WRITTEN PERMISSION OF FREEVBCODE.COM.

ã2000 by FreeVBCode.com Page 1

ASPUPLOAD .DLL

I.  INTRODUCTION/OVERVIEW

Description: AspUpload.dll is a COM component written in Visual Basic 6.0 that allows you to provide upload capabilities to an ASP page. In other words, if you (the web developer) call the methods of this .dll from your web page, you can allow users to upload files to your web host machine.

IT IS IMPORTANT THAT YOU READ THE BELOW INSTRUCTIONS, ESPECIALLY THE “WHAT YOU NEED” AND “LIMITATIONS AND KNOWN ISSUES” SECTIONS. If you don’t follow the instructions exactly as written, the component won’t work. It is assumed you have a basic understanding of ASP and how to instantiate and create COM objects from ASP pages using the Server.CreateObject function.

Implementation/RFC 1867: The component works by reading the entire http request byte by byte and parsing it to determine the file contents, as well as the contents of each name/value pair in your HTML form (e.g., the names and values of text input boxes, select drop-downs, etc.) The parsing is based on the protocol set forth in RFC 1867. For more information about this protocol, see http://www.faqs.org/rfcs/rfc1867.html.

To read the http request, the component uses the BinaryRead method of the built-in ASP request object. ONCE YOU USE THIS METHOD, YOU NO LONGER HAVE ACCESS TO THE REQUEST OBJECT’S FORM COLLECTION. (This is a limitation of ASP itself; it has nothing to do with this component). Therefore, to read the keys and the values of the request’s form collection, you have to use the ASPUpload component’s Form Object. This will be exemplified and explained further below).

If you are interested in more details regarding the implementation, consult the code itself. It is reasonably well commented. The rest of this document will focus on how to use the component.

What You Need: To use this component, you need the following:

·  For the host machine, all the standard stuff you need for ASP and a VB6 COM.dll (i.e., a properly configured IIS server, the VB6 runtime files on your server, etc.). You of course need to register the .dll by running regsvr32.

·  I have no idea if this will work with one of those 3rd party products such as ChiliSoft that let you run ASP pages on non-IIS web servers.

·  For whatever directory you save files to (as specified by the path and/or filename properties, described below), the web user must have write permission. On a public page, the user would be the Anonymous web user; on an Intranet, the user might be an authenticated user within the current or a trusted domain.

·  The web user must have an RFC 1867 compliant web browser, which for IE is version 3.02 or above and Netscape (I think) 4.0 or above.

·  The submitting page must contain an RFC 1867 compliant form, which looks something like this:

<FORM ACTION="UploadDest.asp" ENCTYPE="multipart/form-data" METHOD="POST" >

The EncType statement is required, as is the METHOD= POST part. The action of course, can be any page that invokes the component.

·  On the submitting page, one of the form elements should be a File Input box, which is coded like this:

<INPUT TYPE=FILE NAME="txtFile"> (The name can be whatever you want it to be).

An Introductory Example:

SUBMITTING PAGE HTML (EXCERPT):

<FORM ACTION="UploadDest.asp" ENCTYPE="multipart/form-data" METHOD="POST" >

<TABLE>

<TR>

<TD>File Name</TD>

<TD<INPUT TYPE=FILE NAME="txtFile"</TD>

</TR>

<TR>

<TD>Save File as:</TD<TD>

<INPUT Name = "SaveAs" TYPE = "TEXT"</TD</TR>

</TABLE>

RECEIVING PAGE HTML (EXCERPT)

<%

set oUpload = Server.CreateObject("ASPUpload.clsUpload")

oUpload.Path = “C:\InetPub\wwwroot\uploadedfiles

oUpload.FileName = oUpload.Form(“txtFile”)

if oUpload.Save then

response.write “Uploaded File saved successfully to “ & oUpload.Path & _

oUpload.FileName

else

response.write “File save failed for the following reason: “ & oUpload.Error

End if

%>

II.  INCLUDED IN THIS PACKAGE:

ASPUpload.dll: Compiled version of the component.

ASPUpload.vbp, clsUpload.cls: The source code. Visual Basic 6 or above is required if you want to modify/compile this code.

UploadSource.asp, UploadDest.asp: Sample Asp pages that use the component. See comments within these files for details regarding what is happening. Navigate to UploadSource.asp.

n  ASPUpload.doc: What you are reading right now.

III.  INTERFACE

Public Function Form(sKey As String) As String

THIS IS THE PROPERTY YOU MUST USE INSTEAD OF THE GENERIC REQUEST.FORM COLLECTION. As noted above, because the component uses the Request.BinaryRead method, the Request.Form Collection is disabled.

For example, assume you have a text input box on your submitting HTML form called txtInfo. Usually, you could refer to its contents on the receiving form with Request(“txtInfo”). But if you are using the ASPUpload component, you will get an error if you do this. Instead, you must do something like the following:

Dim myInfo

set oUpload = Server.CreateObject("ASPUpload.clsUpload")

myInfo = oUpload.Form(“txtInfo”)

Public Property Let Path(ByVal NewValue As String)

Public Property Get Path() As String

The value of this property determines where the uploaded file will be saved. Setting this property is optional. You can either set the full path in the filename property, or leave both properties blank, and the file will be saved by default to the same directory where the .dll resides.


Public Property Let FileName(ByVal NewValue As String)

Public Property Get FileName() As String

The value of this property determines what name the uploaded file will be saved as. Setting this property is also optional. If left blank, the user file name will be used (e.g., if the user enters C:\MyFile.txt into the File Input box and you don’t set the FileName property, the file will be saved as MyFile.txt on the server).

Public Function Save() As Boolean

This saves the uploaded file. Read the information for Path and FileName properties to determine how to save a file to a particular location.

Unlike many other ASP components, an error in this method will not kill your asp page display. If there’s an error, your file won’t be saved, but the receiving page will still load. To get information about why the save failed, check the error property (see below).

It’s therefore best to read the return value of the save method. This way you know if the file was actually saved or not without actually having to browse for it on the host machine.

Refer to the Introductory Example earlier in the document to see how this works: AND REMEMBER: The web user must have write permissions for the appropriate directory in order for the save method to work.

Public Property Get Error() As String

This property is automatically set by the page which invokes this component. If an error occurs, it will contain information about what the error was. If there is no error, it will be an empty string.

For an example of how to use this property, refer to the Introductory Example earlier in the document

Public Property Get FormDetails() as clsFormDetails

This returns an object that enhances the functionality of the Form property. It provides a count property, which indicates the number of form input items in the submitted form, and also allows you to access form input values by numerical indices. The public interface to this object is listed and briefly described below:

Public Property Get Count() As Long

The number of items in the submitted HTML form. Similar to Request.Form.Count in ASP.

Public Function Key(ByVal Index As Long) As String

The value of the Key at position Index in the submitted form. Similar to Request.Form.Keys(Index) in ASP.

Public Function Item(ByVal Index As Long) As String

The value of the Item and position Index in the submitted form. Similar to Request.Form.Item(Index) in ASP.

The instancing property is clsFormDetails. set to Public Not Creatable, which means that the FormDetails property is the only way to access an instance of this class.

For an example of how to access and use this object, see the sample asp UploadDest.asp that was included in this package.

IV.  LIMITATIONS AND KNOWN ISSUES

When using this component, keep the following in mind.

·  You can only use it if you have one form on the submitting page. Within that form, you can only have one File input box. If you look at the code, you will probably realize how difficult it would be to modify this component to support multiple forms and file input boxes. But if you are successful at doing so, please let me know.

·  Neither the file upload nor the form features will work with Double-Byte Character Set (DBCS) systems, such as Chinese or Korean.

·  The larger the file you try to upload, the longer the receiving page will take to load. If you plan to deploy this component over the Internet, you will probably find that files of up to 750- 1MB can be uploaded via a dial-up connection without the script timing out. On a corporate Intranet, I got files over 4MB in size to upload. Of course, this will depend on a number of factors, such as the speed of your connection and the route the request travels from client to server. But if you plan to exceed these general guidelines, set the Server.ScriptTimeOut value to a larger value than the default of 90 in your code.

·  I spent most of the development time working on optimizing the speed of uploading. Though I was not able to match the speed of some of the 3rd party components available for sale, I did manage to improve the speed dramatically in the course of development. If you figure out a way to optimize the component further, please let me know.

·  Over 35,000 people have downloaded this component and I have not heard too many reports of bugs, except for the one fixed in release 1.51 (see below). One person could not get it to work when he used it it as an MTS component. Although he eventually found a workaround, I don’t remember what it was and therefore cannot guarantee that the component will work as an MTS component.

V.  Version Information

Version 1.0: Released Q1 2000

Version 1.5: Released 12/26/2000: Enhanced the form-related features by adding the FormDetails object (see Interface for more details).

Version 1.51: Release 02/28/2002: Fixed bug which sometimes prevented text files with the – character from uploading correctly.

ã2000 by FreeVBCode.com Page 1