How to Upload Files to a Server Using ASP

Written by katrina matterhorn
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Upload Files to a Server Using ASP
Upload files to a server with ASP programming scripts. (laptop image by Angie Lingnau from Fotolia.com)

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.

Skill level:
Easy

Other People Are Reading

Instructions

  1. 1

    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.

  2. 2

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

  3. 3

    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."

  4. 4

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

    "<%@ Language=VBScript %>

    <html>

    <head>

    </head>

    <body>

    <form enctype="multipart/form-data" action="uploadfile.asp" method="post" name="main1">

    <input name="file" type="file" size="50">

    <INPUT type="text" id=text1 name=text1><INPUT type="text" id=text2 name=text2>

    <input name="submit" type="submit" value="Upload">

    </form>

    </body>

    </html>."

  5. 5

    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\"

    fuFile.Upload

    If Err.number = 0 Then

    strMsg = fuFile.FileName  &amp; " was uploaded successfully."
    

    Else

    strMsg = "An error occurred when uploading your file: " &amp; Err.Description
    

    End If

    for each o in fuFile.Form

    Response.Write o  &amp; "&lt;BR&gt;"
    
    
    
    next
    
    
    
    Response.Write fuFile.Form.item("text1") &amp; "  :  " &amp; fuFile.Form.item("text2")
    

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

    set fufile = nothing

    %>

    <html>

    <head></head>

    <body>

    <%=strMsg%>

    </body>

    </html>."

  6. 6

    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."

  7. 7

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

  8. 8

    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."

  9. 9

    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."

  10. 10

    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.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.