affordable web development services
| About Us | Services | Download | Order | Support | Subscribe to News Feed Follow us on Twitter Join us on Facebook |
 

ASP Upload Component v1.0 - Documentation

Table of Contents

Description

ASP Upload Component is ActiveX component designed to ease access to multipart/form-data received from client's browser when developing Active Server Pages applications. With this component installed you can access multible file uploads and other form data just the way it is done with Request object.

Features

System Requirements

OS:

Web Server:

Installation Instructions

After receiving archive with ASP Upload component:

  1. Extract all files from zip file to temporary directory
  2. Run Setup.exe
  3. Follow instructions of the installer
  4. Test installation with one of the examples found in the archive

Download Windows Installer if during the installation process you receive following message:

The loader can not find the 'D:\path\to\setup\files\InstMsiW.exe' file
necessary to load the Windows Installer.

Form Setup

For file uploads to be posted properly there are three required attribute settings for sender form:

Other form attributes are not relevant to component functionality. Each form may contain all types of controls in any combinations.

<form method="post" enctype="multipart/form-data" action="demo.asp" name="test_form">
	Specify the File: <input type="File" name="file_upload1"><br>
	Save As: <input type="Text" name="new_filename1"><br>
	Specify the File: <input type="File" name="file_upload2"><br>

	Save As: <input type="Text" name="new_filename2"><br>
	Allow Overwrite: <input type="Checkbox" name="allow_overwrite"><br>
	<input type="Submit" name="Submit" value="Upload!">
</form>

Note: Component can also process form posts without any file uploads. In such case form attribute enctype is not required.

PostStream object

Description

PostStream Object allows access to fields and files posted by HTML form. Poststream object parses data posted by HTML form and presents it to the ASP script as enumerable collection.

Syntax:

VBasic:

Set NewPostStreamObject = Server.CreateObject("SoftComplex.ASP.PostStream")

Jscript:

var NewPostStreamObject = Server.CreateObject("SoftComplex.ASP.PostStream");

Properties:

boolean PostStreamObject.Empty

Read Only property indicating whenever form post took the place. If ASP script was called by Get method this parameter returns false, If ASP script was called by Post method this parameter returns true even if form did not contain any data.

boolean PostStreamObject.Buffer

Read/Write property indicating whenever buffered mode is on. Normally buffered mode should be turned off when large file upload expected. In this case only conseqentive access to the form data is possible (with MoveNext method).

boolean PostStreamObject.EOF

Read Only property indicating whenever end of collection is reached when enumerating it with MoveNext method.

int PostStreamObject.Count

Read Only property, in buffered mode returns number of elements in the collection.

int PostStreamObject.Limit

Read/Write property indicating current upload file limit in bytes. 0 (default) - no limit.

FormItem | FileItem PostStreamObject.Current

Read Only property, returns current element of the collection when enumerating it with MoveNext method.

Methods:

boolean PostStreamObject.MoveNext()

Used for enumerating collection - moves Current property to the next form element or file upload. Method returns false when trying to move after end of collection is reached.

FormItem | FileItem PostStreamObject.Item (int index | string name)
FormItem | FileItem PostStreamObject (int index | string name)

In buffered mode used to access element of the collection with index or HTML form name specified.

FormItem object

Description

FormItem Object represents text based HTML form element (types: Text, Password, Checkbox, Hidden etc.) posted by HTML form.

Syntax:

VBasic:

Set NewFormItemObject = PostStreamObject.Item(int index | string name)
Set NewFormItemObject = PostStreamObject(int index | string name)

Jscript:

var NewFormItemObject = PostStreamObject.Item(int index | string name);
var NewFormItemObject = PostStreamObject(int index | string name);

Properties:

string FormItemObject.Name

Read Only property, returns name attribute of the input tag in the sending HTML form for this element.

string FormItemObject.Value

Read Only property, returns value sent by the input tag for this element.

boolean FormItemObject.File

Read Only property, returns false for FormItem Object. Used to detect type of element.

boolean FormItemObject.Empty

Read Only property, indicating whenever property 'Value' contains empty string.

FileItem object

Description:

FormItem Object represents file upload posted with HTML form.

Syntax:

VBasic:

Set NewFileItemObject = PostStreamObject.Item(int index | string name)
Set NewFileItemObject = PostStreamObject(int index | string name)

Jscript:

var NewFileItemObject = PostStreamObject.Item(int index | string name);
var NewFileItemObject = PostStreamObject(int index | string name);

Properties:

string FileItemObject.Name

Read Only property, returns name attribute of the file input tag in the sending HTML form for this element.

string FileItemObject.Value

Read Only property, returns the content of uploaded file.

boolean FileItemObject.File

Read Only property, returns true for FileItem Object. Used to detect type of element.

boolean FileItemObject.Empty

Read Only property, indicating whenever current file is empty.

boolean FileItemObject.FileName

Read Only property, returns the name of original file in the file system of sender.

Methods:

FileItemObject.Save(string dir_path | string file_path)

Saves this file to drive with filename specified or in the directory specified with the original file name. If path starts from local or network disk name - this path is interpretted as absolute to drive root, if path starts with slash - this path is interpreted as absolute to web site root, if path starts with name - this path is interpreted as relative.

FileItemObject.SaveEx(string dir_path | string file_path, boolean overwrite)

Same as Save method but with additional option to overwrite existing files when saving.

ASP VBasic Demos

Single File Upload

Code below demonstrates VBasic usage of ASP upload component for single file upload in buffered mode. This script also shows how to handle errors when using component.

<%@Language=VBScript%>

<html>
<body>
   <!-- All forms that send files should have attributes set:
               method="post" enctype="multipart/form-data" -->

   <form method="post" enctype="multipart/form-data">
      <input name="file" type="file"><br>
      <input type="submit">
   </form>
   <br>
<%
' enable error handling
On Error Resume Next

' create instance of ASP Upload Component
Set PostStream = Server.CreateObject("SoftComplex.ASP.PostStream")

' ensure that the component instantiated successfully
If Err.Number <> 0 Then
   ' report error if instantiation failed
   ReportError "Can't create ""ASP Upload Component"" component."
' check if any data is available (there is no data when form called with get method)
ElseIf PostStream.Empty Then
   ' print welcome message on form's first load
   Response.Write "Select a file and press ""Submit"" in order to upload it"
Else
   ' check if file submitted contains any data
   FileIsEmpty = PostStream("file").Empty

   If Err.Number <> 0 Then 
      ' transfer unhandled errors - with trial version "Stream limit excided" error
      ReportError   ""
   ElseIf FileIsEmpty Then
      ' report empty file submission
      ReportError "You have submitted an empty file."
   Else
      ' save file on the local drive in the directory of your choice ("uploads") with it's original name
      PostStream("file").Save("uploads")
      If Err.Number <> 0 Then
         ' report error if any
         ReportError "Can't save uploaded file."
      Else
         ' report success
         Response.Write "File """ & PostStream("file").FileName & """ has been successfully uploaded and saved."
      End If
   End If
End If

'Just a simple function to report errors
Function ReportError(message) 
   Response.Write "<font color=""red""><b>"
   
   If message <> "" Then 
      Response.Write message & "<br>"
   End If
   
   If Err.Number <> 0 Then 
      Response.Write "Error: " & Err.Description
   End If
   
   Response.Write "</b></font>"
   Err.Clear
End Function
%>

</body>
</html>

Multiple Files Upload

Code below demonstrates VBasic usage of ASP upload component for multiple file upload in buffered mode. This script also shows how to handle errors when using component.

<%@Language=VBScript%>

<html>
<body>

   <!-- All forms that send files should have attributes set:
               method="post" enctype="multipart/form-data" -->
   <form method="post" enctype="multipart/form-data">
      <input name="file1" type="file"><br>
      <input name="file2" type="file"><br>
      <input name="file3" type="file"><br>

      <input name="file4" type="file"><br>
      <input type="submit">
   </form>
   <br>
<%
' enable error handling
On Error Resume Next

' create instance of ASP Upload Component
Set PostStream = Server.CreateObject("SoftComplex.ASP.PostStream")

' ensure that the component instantiated successfully
If Err.Number <> 0 Then
   ' report error if instantiation failed
   ReportError "Can't create ""ASP Upload Component"" component."
' check if any data is available (there is no data when form called with get method)
ElseIf PostStream.Empty Then
   ' print welcome message on form's first load
   Response.Write "Select a file and press ""Submit"" in order to upload it"
Else
   Do
      ' obtain the next file filed
      Set file = PostStream.Current
      If Err.Number <> 0 Then 
         ' transfer unhandled errors - with trial version "Stream limit excided" error
         ReportError   ""
         Exit Do
      ElseIf file.Empty Then
         ' report empty file submission
         If file.FileName <> "" Then
            ReportError file.FileName & " is empty."
         Else
            ReportError "Form field """ & file.Name & """ is not filled."
         End If
      Else
         ' save file on the local drive in the directory of your choice ("uploads") with it's original name
         file.Save("uploads")
         If Err.Number <> 0 Then
            ' report error if any
            ReportError "Can't save """ & file.FileName & """."
         Else
            ' report success
            Response.Write "File """ & file.FileName & """ has been successfully uploaded and saved."
         End If
      End If
      Response.Write "<br>"
   ' move to the next field until end
   Loop While PostStream.MoveNext
End If

'Just a simple function to report errors
Function ReportError(message) 
   Response.Write "<font color=""red""><b>"
   
   If message <> "" Then 
      Response.Write message 
   End If
   
   If Err.Number <> 0 Then 
      If message <> "" Then
         Response.Write "<br>"
      End If
      Response.Write "Error: " & Err.Description
   End If
   
   Response.Write "</b></font>"
   Err.Clear
End Function
%>

</body>
</html>

Multiple Files Mixed Upload

Code below demonstrates VBasic usage of ASP upload component for multiple files upload together with text based fields submission in buffered mode. This script also shows how to handle errors when using component.

<%@Language=VBScript%>

<html>
<body>

   <i>* file name to save file as / overwrite flag / file to upload </i>
   <!-- All forms that send files should have attributes set:
               method="post" enctype="multipart/form-data" -->
   <form method="post" enctype="multipart/form-data">
      <input name="saveas1" type="text"> <input type="checkbox" name="overwrite1"> <input name="file1" type="file"><br>

      <input name="saveas2" type="text"> <input type="checkbox" name="overwrite2"> <input name="file2" type="file"><br>
      <input name="saveas3" type="text"> <input type="checkbox" name="overwrite3"> <input name="file3" type="file"><br>
      <input name="saveas4" type="text"> <input type="checkbox" name="overwrite4"> <input name="file4" type="file"><br>

      <input type="submit">
   </form>
   <br>
<%
' enable error handling
On Error Resume Next

' create instance of ASP Upload Component
Set PostStream = Server.CreateObject("SoftComplex.ASP.PostStream")

' ensure that the component instantiated successfully
If Err.Number <> 0 Then
   ' report error if instantiation failed
   ReportError "Can't create ""ASP Upload Component"" component."
' check if any data is available (there is no data when form called with get method)
ElseIf PostStream.Empty Then
   ' print welcome message on form's first load
   Response.Write "Select a file and press ""Submit"" in order to upload it"
Else
   
   For index=1 to 4
   
      ' obtain the file filed
      Set file = PostStream("file" & index)
      
      If Err.Number <> 0 Then 
         ' transfer unhandled errors - with trial version "Stream limit excided" error
         ReportError   ""
         Exit For
      End If
      
      ' obtain the "save as" filed value
      saveAs = PostStream("saveas" & index)
      ' obtain the "overwrite" filed value
      overwrite = PostStream("overwrite" & index)
      
      If file.Empty Then
         ' report empty file submission
         If file.FileName <> "" Then
            ReportError file.FileName & " is empty."
         Else
            ReportError "Form field """ & file.Name & """ is not filled."
         End If
      Else
         ' save file on the local drive in the directory of your choice ("uploads") with it's original name
         file.SaveEx "uploads/" & saveAs, overwrite = "on"
         If Err.Number <> 0 Then
            ' report error if any
            ReportError "Can't save """ & file.FileName & """."
         Else
            ' report success
            Response.Write "File """ & file.FileName & """ has been successfully uploaded and saved"
            If saveAs <> "" Then
               Response.Write " as """ & saveAs & """."
            Else
               Response.Write "."
            End If
         End If
      End If
      Response.Write "<br>"
   ' move to the next field until end
   Next
End If

'Just a simple function to report errors
Function ReportError(message) 
   Response.Write "<font color=""red""><b>"
   
   If message <> "" Then 
      Response.Write message 
   End If
   
   If Err.Number <> 0 Then 
      If message <> "" Then
         Response.Write "<br>"
      End If
      Response.Write "Error: " & Err.Description
   End If
   
   Response.Write "</b></font>"
   Err.Clear
End Function
%>

</body>
</html>

Multiple Files Mixed Upload Unbuffered

Code below demonstrates VBasic usage of ASP upload component for multiple files upload together with text based fields submission in unbuffered mode. This script also shows how to handle errors when using component.

<%@Language=VBScript%>

<html>
<body>

   <i>* file name to save file as / overwrite flag / file to upload </i>
   <!-- All forms that send files should have attributes set:
               method="post" enctype="multipart/form-data" -->
   <form method="post" enctype="multipart/form-data">
      <input name="saveas1" type="text"> <input type="checkbox" name="overwrite1"> <input name="file1" type="file" ID="File1"><br>

      <input name="saveas2" type="text"> <input type="checkbox" name="overwrite2"> <input name="file2" type="file" ID="File2"><br>
      <input name="saveas3" type="text"> <input type="checkbox" name="overwrite3"> <input name="file3" type="file" ID="File3"><br>
      <input name="saveas4" type="text"> <input type="checkbox" name="overwrite4"> <input name="file4" type="file" ID="File4"><br>

      <input type="submit">
   </form>
   <br>
<%
' enable error handling
On Error Resume Next

' create instance of ASP Upload Component
Set PostStream = Server.CreateObject("SoftComplex.ASP.PostStream")
' turn off buffering in order to minimize system resources usage (by default it's turned on)
PostStream.Buffer = false

' ensure that the component instantiated successfully
If Err.Number <> 0 Then
   ' report error if instantiation failed
   ReportError "Can't create ""ASP Upload Component"" component."
' check if any data is available (there is no data when form called with get method)
ElseIf PostStream.Empty Then
   ' print welcome message on form's first load
   Response.Write "Select a file and press ""Submit"" in order to upload it"
Else
   
   Do
      Dim saveAs, overwrite, file
      ' obtain the "save as" filed value
      saveAs = PostStream.Current
      ' obtain the "overwrite" filed value
      PostStream.MoveNext
      ' obtain the file filed
      If PostStream.Current.File Then
         Set file = PostStream.Current
         overwrite = "off"
      Else
         overwrite = PostStream.Current
         PostStream.MoveNext
         Set file = PostStream.Current
      End If
      
      If Err.Number <> 0 Then 
         ' transfer unhandled errors - with trial version "Stream limit excided" error
         ReportError   ""
         Exit Do
      End If
      
      
      If file.Empty Then
         ' report empty file submission
         If file.FileName <> "" Then
            ReportError file.FileName & " is empty."
         Else
            ReportError "Form field """ & file.Name & """ is not filled."
         End If
      Else
         ' save file on the local drive in the directory of your choice ("uploads") with it's original name
         file.SaveEx "uploads/" & saveAs, overwrite = "on"
         If Err.Number <> 0 Then
            ' report error if any
            ReportError "Can't save """ & file.FileName & """."
         Else
            ' report success
            Response.Write "File """ & file.FileName & """ has been successfully uploaded and saved"
            If saveAs <> "" Then
               Response.Write " as """ & saveAs & """."
            Else
               Response.Write "."
            End If
         End If
      End If
      Response.Write "<br>"
      
      ' move to the next field until end
   Loop While PostStream.MoveNext
   
End If

'Just a simple function to report errors
Function ReportError(message) 
   Response.Write "<font color=""red""><b>"
   
   If message <> "" Then 
      Response.Write message 
   End If
   
   If Err.Number <> 0 Then 
      If message <> "" Then
         Response.Write "<br>"
      End If
      Response.Write "Error: " & Err.Description
   End If
   
   Response.Write "</b></font>"
   Err.Clear
End Function
%>

</body>
</html>

Terms and Conditions

Single Server License

One single server ASP Upload Component license gives the right to use one installation of the component. Component can be used by unlimited number of sites/domains hosted on the server.

Single Organization License

One single organization ASP Upload Component license gives the right to use unlimited installations of the component within single organization network.

Developer License

Developer license gives the right to include unlimited number of ASP Upload Component instances in the products of license owner. Such kind of license is obtained automatically by those who has 5 or more single licenses of any type above.

Discounts

After license order customers are offered special (significantly discounted) prices for other products of SoftComplex.

Usage

As owner of the ASP Upload Component license You are allowed to use the component in any possible way in Internet (public), Intranet (corporate), however You are strictly NOT allowed (unless specifically authorized by SoftComplex.com) to:

Technical Support

You are entitled to free product upgrades and technical support for at least one year from the date of purchase. Technical support includes answers to script related questions via via e-mail and/or Internet instant messaging services.

Violations of Terms and Conditions

Should you violate these Terms and Conditions or any other rights of SoftComplex Inc., SoftComplex Inc. reserves the right to pursue any and all legal and equitable remedies against you without limitation.

Links and References