How to do a multiple file upload? RRS feed

  • Question

  • User1452403003 posted

    Has anyboady added a multiple file upload to their site? I viewed the videos in the learn section, but it only shows how to upload to a folder on your hard drive and not to a database. Any help would be appreciated.


    Thursday, February 12, 2009 10:12 PM

All replies

  • User-137998610 posted

    May this might be of any help:

    Protected Sub Upload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Upload.Click
            Dim fileUpload1 As FileUpload = CType(Me.FindControl("fileUpload1"), FileUpload)
            'Make sure a file has been successfully uploaded
            If fileUpload1.PostedFile Is Nothing OrElse String.IsNullOrEmpty(fileUpload1.PostedFile.FileName) OrElse fileUpload1.PostedFile.InputStream Is Nothing Then
                Label1.Text = "Please Upload Valid picture file"
                Exit Sub
            End If
            'Make sure we are dealing with a JPG or GIF file
            Dim extension As String = System.IO.Path.GetExtension(fileUpload1.PostedFile.FileName).ToLower()
            Dim MIMEType As String = Nothing
            Select Case extension
                Case ".gif"
                    MIMEType = "image/gif"
                Case ".jpg", ".jpeg", ".jpe"
                    MIMEType = "image/jpeg"
                Case ".png"
                    MIMEType = "image/png"
                Case Else
                    'Invalid file type uploaded
                    Label1.Text = "Not a Valid file format"
                    Exit Sub
            End Select
            'Connect to the database and insert a new record into Products
            Using myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("ImageGalleryConnectionString").ConnectionString)
                Const SQL As String = "INSERT INTO [Pictures] ([Title], [MIMEType], [Image]) VALUES (@Title, @MIMEType, @ImageData)"
                Dim myCommand As New SqlCommand(SQL, myConnection)
                myCommand.Parameters.AddWithValue("@Title", TextBox1.Text.Trim())
                myCommand.Parameters.AddWithValue("@MIMEType", MIMEType)
                'Load FileUpload's InputStream into Byte array
                Dim imageBytes(fileUpload1.PostedFile.InputStream.Length) As Byte
                fileUpload1.PostedFile.InputStream.Read(imageBytes, 0, imageBytes.Length)
                myCommand.Parameters.AddWithValue("@ImageData", imageBytes)
            End Using
        End Sub


    Mark it as answer if it helps you.


    Saturday, February 14, 2009 4:31 AM