How to use ASP Simple Upload component?

Sample code:

  1. <%
  2. Option Explicit
  3. Dim upl, NewFileName
  4. Set upl = Server.CreateObject("ASPSimpleUpload.Upload")
  5. If Len(upl.Form("File1")) > 0 Then
  6. NewFileName = "/Uploads/" & upl.ExtractFileName(upl.Form("File1"))
  7. If upl.SaveToWeb("File1", NewFileName) Then
  8. Response.Write("File successfully written to disk.")
  9. Else
  10. Response.Write("There was an error saving the file to disk.")
  11. End If
  12. End If
  13. %>
  14. <html> <head> <title> ASP Simple Upload Example #1 </title> </head>
  15. <body>
  16. <form action="Example1.Asp" enctype="multipart/form-data" method="POST">
  17. Select a file to upload: <input name="File1" size="30" type="file">
  18. <input name="submit" type="submit" value="Upload Now">
  19. </form>
  20. <body>
  21. <html>


Line # description

  1. Starts the ASP code section of the file.
  2. Forces us to declare all of our variables.
  3. Declare the variables that we're going to use in the code.
  4. Create an instance of the Upload component so we can use it throughout the code.
  5. Check to see if the users uploaded a file. If they did, this will contain the name of the file on their hard drive. Also, note that we us the component to get the form fields, not the Request object. You must use the component to read the form variables in all of the forms with file uploads on them.
  6. Set the NewFileName variable to the /Uploads/ directory in our web server root and append just the name of the file that was uploaded.
  7. Save the file to our web server. This method automatically calls the Server.MapPath for you so you don't have to figure out where your website is physically located. The first parameter of SaveToWeb is the field name (File1) and the second parameter is the location and filename you want to save this file to.
  8. If the save was successful, we tell the user.
  9. Otherwise, tell them the upload failed.
  10. End the ASP part of the page.
  11. Start our form making sure to set the method to POST and the enctype to multipart/form-data.
  12. Add the file input tag to the form with the type of file and the form field name of File1 and a form field length (on the screen) of 30.
  13. Add the submit button to the form, so that after they select a file to upload, they can submit it to this page for processing.
  14. End the form.

Note: This may please be noted that this component can be uniformly used by all the users of Windows Shared Hosting.

  • 327 Users Found This Useful

Was this answer helpful?

Related Articles

How to create ASPNETDB database using aspnet_regsql tool?

What is ASPNETDB? Microsoft has introduced a new and powerful default database schema in...

How to send emails through JMail?

We have installed JMail on our Windows shared servers. You can use following sample script to...

How to use Dundas Mailer?

A. Sending an Email with the QuickSend Method <% Dim objMailer 'Mailer control Set...

Microsoft Access and ASP connection script for Windwos 2008 / 2012 shared hosting

If your website is hosted on our Windows 2008 or Windows 2012 shared hosting server, you will...

How to use ASPSMS?

Here is the ASP VB-Script example, intended to be used on an IIS (Internet Information Server)...