?
Solved

image upload using vb.net

Posted on 2004-11-10
14
Medium Priority
?
308 Views
Last Modified: 2008-03-17
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
0
Comment
Question by:code1994
  • 6
  • 4
11 Comments
 

Author Comment

by:code1994
ID: 12551998
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
 
LVL 4

Expert Comment

by:vinhthuy_nguyen
ID: 12552453
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
 

Author Comment

by:code1994
ID: 12553309
hi, the code is return in aspx page not on aspx.vb

can i put the code into .vb ?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:vinhthuy_nguyen
ID: 12553720
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
 

Author Comment

by:code1994
ID: 12555043
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
 

Author Comment

by:code1994
ID: 12555237
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
 
LVL 4

Expert Comment

by:vinhthuy_nguyen
ID: 12555519
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
 

Author Comment

by:code1994
ID: 12555534
i want on the client side validation like javascript please
0
 

Author Comment

by:code1994
ID: 12555606
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
 
LVL 4

Expert Comment

by:vinhthuy_nguyen
ID: 12555639
sorry, I mixed up. Hope anyone can help you with Javascript, I don't dig much in it.
0
 
LVL 3

Accepted Solution

by:
gbelken99 earned 200 total points
ID: 12708018
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question