How to Upload Multiple Images in ASP Net

Written by jeff grundy Google
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Upload Multiple Images in ASP Net
(Comstock/Comstock/Getty Images)

If you have a website on a Windows-based Web server, you probably use Active Server Pages (ASP) in some fashion or another. If your site allows users to upload images or photos to the server, you can make things considerably easier for your visitors by providing them a means of uploading multiple images at once. With Visual Basic or Visual Studio, adding multiple ASP file/image upload controls to a page or Web application is as easy as dragging and dropping controls to your project form and then adding a few lines of code.

Skill level:
Easy

Other People Are Reading

Things you need

  • Visual Basic or Visual Studio

Show MoreHide

Instructions

  1. 1

    Launch Visual Basic or Visual Studio, then open the ASP Web form or project in which you want to include multi-file upload code. Alternatively, click "File/New" to create a new ASP Web form or project.

  2. 2

    Locate the "Toolbox" on the toolbar. If the "Toolbox" is not visible, click the "View" option on the menu bard, then click "View Toolbox."

  3. 3

    Click the "FileUpload" control in the "Toolbox" section, then drag and drop the "FileUpload" control to your Web form. Drop additional "FileUpload" controls on your form as needed. The number of controls you drag to your form will depend upon how many individual files you want to allow your users to upload in one session. The "FileUpload" control allows users to browse for files on their hard drive that they wish to upload to a website.

  4. 4

    Drag a "Button" control from the "Toolbox," then drop it onto your Web form beneath the final "FileUpload" control. Highlight the button, press the "F2" key and then rename the button control "Upload" or something similar. The "Button" control allows users to submit files after having located the files on their hard drive.

  5. 5

    Double-click on the new "Upload" or similarly named control, then enter the following code in the event handler field:

    "Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As EventArgs)

    End Sub"

  6. 6

    Copy and paste the following code into the body of the Web form:

    "Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As EventArgs)

    Try

    ' Get the HttpFileCollection

    Dim hfc As HttpFileCollection = Request.Files

    For i As Integer = 0 To hfc.Count -- 1

    Dim hpf As HttpPostedFile = hfc(i)

    If hpf.ContentLength > 0 Then

    hpf.SaveAs(Server.MapPath("MyFiles") & "\" & Path.GetFileName(hpf.FileName))

    End If

    Next i

    Catch ex As Exception

    ' Enter any custom error handling code here

    End Try

    End Sub"

  7. 7

    Save the ASP form, then log in to your Web hosting control panel. Upload the form to your Windows Web server.

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.