Click here to Skip to main content
13,736,794 members
Rate this:
Please Sign up or sign in to vote.
See more:

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

            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
                        lblMsg.ForeColor = System.Drawing.Color.Red
                        lblMsg.Text = "Photo extension " & ext & " is not accepted."
                    End If
                End If
            Next i
Posted 9-Nov-17 20:09pm
Updated 13-Nov-17 20:40pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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 ...

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web05-2016 | 2.8.180920.1 | Last Updated 14 Nov 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100