We Value Your Privacy

We and our partners use technology such as cookies on our site to personalise content and ads, provide social media features, and analyse our traffic. Click below to consent to the use of this technology across the web. You can change your mind and change your consent choices at anytime by returning to this site.

Update Consent
Loading ...

How to Upload Files to a Server Using ASP

Updated April 17, 2017

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.

Loading ...
  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. Click "ASPFileUpload Properties" under the "Project" tab. Choose "Unattended Execution" and "Retained In Memory" under the "Project Properties" box, and click "OK."

  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. Paste the following ASP code into a text editor such as notepad ,and save it as "PostFile.asp" :

  5. "<%@ Language=VBScript %>

  6. ."

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

  8. "<%@ Language=VBScript %>

  9. <%
  10. '//////////////////////////////////////////////////////////////////////////////////

  11. '// ASPFileUpload.File API

  12. '//

  13. '// Properties

  14. '// Filename

  15. '// - Read/Write

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

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

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

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

  20. '//

  21. '// Overwrite

  22. '// - Read/Write

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

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

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

  26. '//

  27. '// Target

  28. '// - Read/Write

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

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

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

  32. '//

  33. '// Form

  34. '// - ReadOnly

  35. '// - Scripting.Dictionary object

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

  37. '// - Acts like the asp form collection.

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

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

  40. '//

  41. '// Methods

  42. '// Upload

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

  44. '//

  45. '// Other

  46. '// - ASPFileUpload requires COM+

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

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

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

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

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

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

  53. '//

  54. '//////////////////////////////////////////////////////////////////////////////////

  55. Dim strMsg 'As String

  56. ' On Error Resume Next

  57. dim fuFile

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

  59. 'Set the destination folder.

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

  61. fuFile.Upload

  62. If Err.number = 0 Then

  63. Else

  64. End If

  65. for each o in fuFile.Form

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

  67. set fufile = nothing

  68. %>

  69. <%=strMsg%>
  70. ."

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

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

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

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

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

Loading ...

About the Author

Katrina Matterhorn is experienced in technology consulting for two of the largest technology companies in the world. Since 2009 she has specialized in technology, business and home and garden articles. She has a double major in English and political science from Austin College in addition to Microsoft and IBM certifications.

Loading ...