Click here to Skip to main content
15,891,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm currently developing a vb web application. One of them is uploading image into the gallery in db. I have two different FileUpload control: FileUpload1 and FileUpload2.

FileUpload1 is for album cover (image)
FileUpload2 is for the images in the album (multi image)

Both images from the FileUpload1 and FileUpload2 will be stored in the same table except that FileUpload1 will have an additional flag which will determine either the image in the table is the album cover or not

Below is the my current code for fileUpload2. It's working fine. However I have trouble to differentiate the image from which file upload control so that I can put the flag

What I have tried:

Dim hfc As HttpFileCollection = Request.Files
        Dim imagePath As String = FileUpload2.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 = "jpeg"
                            Exit Select
                        Case ".jpeg"
                            contenttype = "jpeg"
                            Exit Select
                        Case ".png"
                            contenttype = "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
                        insertData()
                    Else
                        lblMsg.ForeColor = System.Drawing.Color.Red
                        lblMsg.Text = "Photo extension " & ext & " is not accepted."
                    End If
                End If
            Next i
Posted
Updated 13-Nov-17 20:40pm
v4

1 solution

I suppose (not sure) that you work with global variables all the time.
I also suppose that you call (or want to call) the Method 'insertData' either from FileUpload1 or FileUpload2.
So ... I suggest you think about working with parameterized Method-calls. This will allow you 'tell' the called method to act in different ways.
Perhaps you re-think your programming-style ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900