image upload using vb.net

hello:

im trying to upload the images to server i have code for that and its work fine
but i have 3 input box and i have to write the same code 3 times but instead of writing 3 times same code except the change of input id name. my question that, how can i convert my code into for - next loop so that regardles how many input i have, i just need to pass how many i have in my form

<input id="fileupload1" style="Z-INDEX: 116; LEFT: 147px; POSITION: absolute; TOP: 149px"
type="file" name="fileupload1" runat="server">

<input id="fileupload1" style="Z-INDEX: 116; LEFT: 147px; POSITION: absolute; TOP: 149px"
type="file" name="fileupload1" runat="server">

<input id="fileupload1" style="Z-INDEX: 116; LEFT: 147px; POSITION: absolute; TOP: 149px"
type="file" name="fileupload1" runat="server">


If Len(fileupload1.Value) > 0 Then
            If Not (fileupload1.PostedFile Is Nothing) Then 'Check to make sure we actually have a file to upload
                'Dim strLongFilePath As String =
                strLongFilePath = fileupload1.PostedFile.FileName()
                'Dim intFileNameLength As Integer =
                intFileNameLength = InStr(1, StrReverse(strLongFilePath), "\")
                'Dim strFileName As String =
                strFileName = Mid(strLongFilePath, (Len(strLongFilePath) - intFileNameLength) + 2)

                Select Case fileupload1.PostedFile.ContentType
                    Case "image/pjpeg", "image/jpeg", "image/gif", "image/bmp"    'Make sure we are getting a valid JPG image
                        'fileupload1.PostedFile.SaveAs(Server.MapPath("\uploadimages\") & strFileName)
                        fileupload1.PostedFile.SaveAs(ConfigurationSettings.AppSettings("FilePath") & "\" & strFileName)
                        lbStatus.Text = strFileName & " was uploaded successfully to: " & Server.MapPath("\") & strFileName
                    Case Else
                        'Not a valid jpeg image
                        lbStatus.Text = "Not a valid jpeg image"
                End Select
            End If
        End If
code1994Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

code1994Author Commented:
sorry

fileupload1
fileupload2
fileupload3

<input id="fileupload1" style="Z-INDEX: 116; LEFT: 147px; POSITION: absolute; TOP: 149px"
type="file" name="fileupload1" runat="server">

<input id="fileupload2" style="Z-INDEX: 116; LEFT: 147px; POSITION: absolute; TOP: 149px"
type="file" name="fileupload1" runat="server">

<input id="fileupload3" style="Z-INDEX: 116; LEFT: 147px; POSITION: absolute; TOP: 149px"
type="file" name="fileupload1" runat="server">
0
vinhthuy_nguyenCommented:
Hi code1994,
You can use HttpFileCollection like :
System.Web.HttpFileCollection _files = System.Web.HttpContext.Current.Request.Files;
to loop through the files upload.
Pls check here for more information
http://www.codetoad.com/asp.net_multiplefileupload.asp 
Nice day

0
code1994Author Commented:
hi, the code is return in aspx page not on aspx.vb

can i put the code into .vb ?
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

vinhthuy_nguyenCommented:
Yes, ofcourse
Put it in Click Event of your upload button
Sub UploadMultipleFiles_Clicked(ByVal Sender As Object, ByVal e As EventArgs) handles your_upload_button.OnClick
0
code1994Author Commented:
i able to put the code on .vb but  i run one small problem

i want to check what type of file they are uploading right now im restricting to jpg/gif/bmp can you shed some light on this please?

thank you
0
code1994Author Commented:
i want to do the validation on aspx page like in javascript  of aspx

if the user upload other then the jpg/gif/bmp and hit submit should give the alert that they can not upload

thanks
0
vinhthuy_nguyenCommented:
Hi, you can use like this :
Select Case strFile.PostedFile.ContentType
                    Case "image/pjpeg"
                        Upload()
                    Case "image/jpg"
                        Upload()
                    Case "image/gif"
                        Upload()
                    Case Else
                                                response.write(strFile.PostedFile.ContentType + " : Not a valid Picture")
                End Select
0
code1994Author Commented:
i want on the client side validation like javascript please
0
code1994Author Commented:
i have some code but its not working propery:

pic = is the name of my texbox

but i want to make this more like a general fucntion anybody can use

i have like 3 input

function check() {
alert("imhere");
  var ext = document.all.pic.value;
  ext = ext.substring(ext.length-3,ext.length);
  ext = ext.toLowerCase();
  if(ext != 'jpg') {
    alert('You selected a .'+ext+' file; please select a .jpg file instead!');
    return false; }
  else
    return true;  
}
0
vinhthuy_nguyenCommented:
sorry, I mixed up. Hope anyone can help you with Javascript, I don't dig much in it.
0
gbelken99Commented:
This link has the example you are looking for I have used it.  I think this method would better suit your needs.  It will allow you to basically upload as many files as needed.
http://www.codeproject.com/aspnet/multiuploads.asp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.