Click here to Skip to main content
13,248,927 members (40,583 online)
Rate this:
 
Please Sign up or sign in to vote.
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 9-Nov-17 21:09pm
Mare7383
Updated 4 days ago
v4

1 solution

Rate this: bad
 
good
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 ...
  Permalink  

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 |
Web01 | 2.8.171114.1 | Last Updated 14 Nov 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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