How to Upload Files to a Server Using ASP

laptop image by Angie Lingnau from

Active Server Pages (ASP) are script engines for dynamic web pages. It offers built-in objects such as server, session, request, response and application for your webpage set up. It is designed by Microsoft and was originally released as an add-on to Internet Information Services. It's now a free feature included with Windows servers. ASP pages can be written using VBScript, PerlScript and JScript. Uploading files to a server using ASP requires a few steps to configure.

Open your Visual Basic application, and open a new "ActiveX DLL" project. Title the project "ASPFileUpload." Change "Class1" to "File." Click "References" within the "Project" pane. Select "Visual Basic For Applications," "Visual Basic Runtime Objects and Procedures," "Visual Basic Objects and Procedures," "OLE Automation," "COM+ Services Type Library," and "Microsoft Active Server Pages Object Library," "Microsoft Scripting Runtime" within the "References" pane.

Click "ASPFileUpload Properties" under the "Project" tab. Choose "Unattended Execution" and "Retained In Memory" under the "Project Properties" box, and click "OK."

Type the code in to "File.cls": on the Microsoft page (see Resources) under "Step 8" beneath "Microsoft Visual Basic 6 Project Setup and Code."

Paste the following ASP code into a text editor such as notepad ,and save it as "PostFile.asp" :

"<%@ Language=VBScript %>


Enter this code into your text editor and save it as "UploadFile.asp" :

"<%@ Language=VBScript %>



'// ASPFileUpload.File API


'// Properties

'// Filename

'// - Read/Write

'// - The file will be saved with this file name.

'// - This property can only be set before calling Upload.

'// - If no value is specified, the original file name

'// - in the HTTP post will be used.


'// Overwrite

'// - Read/Write

'// - This property can only be set before calling Upload.

'// - If set to false and if the destination file exists, an error

'// - is raised. The default value is False.


'// Target

'// - Read/Write

'// - The file will be written to this folder.

'// - This property can only be set before calling Upload.

'// - There is no default value for this property and it is required.


'// Form

'// - ReadOnly

'// - Scripting.Dictionary object

'// - Can access a specific item by using aspfileupload.Form("item").

'// - Acts like the asp form collection.

'// - Can enumerate all values in a collection with for each.

'// - Only filled after the Upload method is called.


'// Methods

'// Upload

'// - This method parses the HTTP Post and writes the file.


'// Other

'// - ASPFileUpload requires COM+

'// - Any call to the Request.Form() collection will cause the Upload

'// method to fail as the method references the Binary contents of the

'// Request object through the Request.BinaryRead method.

'// - Also, if you access a variable in the Request collection without

'// specifying the subcollection that it belongs to, the Request.Form collection

'// may be searched. This causes an error in the Upload method.



Dim strMsg 'As String

' On Error Resume Next

dim fuFile

set fuFile = server.CreateObject("aspFileupload.file")

'Set the destination folder.

fuFile.Target = "C:\TEMP\AspFileUpload\"


If Err.number = 0 Then


End If

for each o in fuFile.Form

' Response.Write Request.Form("test")

set fufile = nothing




Create a folder on the web server that will receive the uploaded files and name it "C:\TEMP\AspFileUpload." Copy and paste your "ASPFileUpload.dll" to your web server, and register it with this command prompt: "regsvr32 PathToDLL\ASPFileUpload.dll." Set your file permissions to allow access to users you designate. Click "Start" and "Settings," and then click "Control Panel."

Click "Administrative Tools" and click "Component Services." Enlarge "Component Services," "Computers," "My Computer," and "COM+ Applications" nodes. Right-click the node, and click "Application."

Click "Create an Empty Application" within the "Install or Create a New Application" box. Designate a name for it, and choose "Server Application," then click "Next." Select "This User" within the "Set Application Identity" box, and enter a user name and password for the account. Click "Finish," and enlarge the application node. Right-click the node, select "New," and click "Component." Click "Install New Components," and browse to your ".dll" file, click it, click "Next," and click "Finish."

Copy and paste your "PostFile.asp" file and your "UploadFile.asp" file to your web root folder, which should look like this "C:\Inetpub\Wwwroot." Modify the target file folder to look like what you created in step one: "fuFile.Target = "C:\TEMP\AspFileUpload."

Upload your file in your web browser by entering the following URL: "http://YourWebServer/Postfile.asp." Change "YourWebServer" to your own. Choose the file you wish to upload, and click "Upload." Verify your uploaded file by checking your upload folder, as it should appear there. You have now uploaded files to a server using ASP.

Most recent