I need to differentiate image between 2 file upload control: FileUpload1 and FileUpload2. My current code works fine but it actually upload images from both FileUpload1 and FileUpload2. How do I specify the file from FileUpload1 and FileUpload2. Below is my current code:

        Dim hfc As HttpFileCollection = Request.Files
        Dim imagePath As String = FileUpload1.PostedFile.FileName
        Dim imagesize As String
        Dim imagename As String = Path.GetFileName(imagePath)
        Dim ext As String
        Dim contenttype As String = String.Empty

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

                Dim hpf As HttpPostedFile = hfc(i)

                ext = Path.GetExtension(hpf.FileName)
                imagesize = hpf.ContentLength

                If hpf.ContentLength > 0 Then
                    'Set the contenttype based on File Extension'
                    Select Case ext
                        Case ".jpg"
                            contenttype = "image/jpeg"
                            Exit Select
                        Case ".jpeg"
                            contenttype = "image/jpeg"
                            Exit Select
                        Case ".png"
                            contenttype = "image/png"
                            Exit Select
                    End Select

                    If contenttype <> String.Empty Then
                        Dim fs As Stream = hpf.InputStream
                        Dim br As New BinaryReader(fs)
                        Dim bytes As Byte() = br.ReadBytes(fs.Length)

                        ViewState("imageName") = hpf.FileName
                        ViewState("imageType") = contenttype
                        ViewState("imageContent") = bytes
                        ViewState("imageLength") = imagesize
                        insertImage() ' SP Insert query'
                    Else
                        lblMsg.ForeColor = System.Drawing.Color.Red
                        lblMsg.Text = "Photo type " & ext & " is not accepted."
                    End If
                End If
            Next i

        Catch except As SqlException
            Throw except
        Catch ex As Exception
            Throw ex
        End Try

I think your question needs clarifying. As it stands I read your question then look over the code and can't find upload2 in the code. So I thought, forget the code, read what they wrote. That didn't help either.

Try again and state what you were trying to accomplish. Also read https://www.daniweb.com/programming/threads/435023/read-this-before-posting-a-question

If you did find a solution, just add that here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.