code1994
asked on
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.Fil eName()
'Dim intFileNameLength As Integer =
intFileNameLength = InStr(1, StrReverse(strLongFilePath ), "\")
'Dim strFileName As String =
strFileName = Mid(strLongFilePath, (Len(strLongFilePath) - intFileNameLength) + 2)
Select Case fileupload1.PostedFile.Con tentType
Case "image/pjpeg", "image/jpeg", "image/gif", "image/bmp" 'Make sure we are getting a valid JPG image
'fileupload1.PostedFile.Sa veAs(Serve r.MapPath( "\uploadim ages\") & strFileName)
fileupload1.PostedFile.Sav eAs(Config urationSet tings.AppS ettings("F ilePath") & "\" & 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
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.Fil
'Dim intFileNameLength As Integer =
intFileNameLength = InStr(1, StrReverse(strLongFilePath
'Dim strFileName As String =
strFileName = Mid(strLongFilePath, (Len(strLongFilePath) - intFileNameLength) + 2)
Select Case fileupload1.PostedFile.Con
Case "image/pjpeg", "image/jpeg", "image/gif", "image/bmp" 'Make sure we are getting a valid JPG image
'fileupload1.PostedFile.Sa
fileupload1.PostedFile.Sav
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
Hi code1994,
You can use HttpFileCollection like :
System.Web.HttpFileCollect ion _files = System.Web.HttpContext.Cur rent.Reque st.Files;
to loop through the files upload.
Pls check here for more information
http://www.codetoad.com/asp.net_multiplefileupload.asp
Nice day
You can use HttpFileCollection like :
System.Web.HttpFileCollect
to loop through the files upload.
Pls check here for more information
http://www.codetoad.com/asp.net_multiplefileupload.asp
Nice day
ASKER
hi, the code is return in aspx page not on aspx.vb
can i put the code into .vb ?
can i put the code into .vb ?
Yes, ofcourse
Put it in Click Event of your upload button
Sub UploadMultipleFiles_Clicke d(ByVal Sender As Object, ByVal e As EventArgs) handles your_upload_button.OnClick
Put it in Click Event of your upload button
Sub UploadMultipleFiles_Clicke
ASKER
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
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
ASKER
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
if the user upload other then the jpg/gif/bmp and hit submit should give the alert that they can not upload
thanks
Hi, you can use like this :
Select Case strFile.PostedFile.Content Type
Case "image/pjpeg"
Upload()
Case "image/jpg"
Upload()
Case "image/gif"
Upload()
Case Else
response.write(strFile.Pos tedFile.Co ntentType + " : Not a valid Picture")
End Select
Select Case strFile.PostedFile.Content
Case "image/pjpeg"
Upload()
Case "image/jpg"
Upload()
Case "image/gif"
Upload()
Case Else
response.write(strFile.Pos
End Select
ASKER
i want on the client side validation like javascript please
ASKER
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.lengt h);
ext = ext.toLowerCase();
if(ext != 'jpg') {
alert('You selected a .'+ext+' file; please select a .jpg file instead!');
return false; }
else
return true;
}
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 = ext.toLowerCase();
if(ext != 'jpg') {
alert('You selected a .'+ext+' file; please select a .jpg file instead!');
return false; }
else
return true;
}
sorry, I mixed up. Hope anyone can help you with Javascript, I don't dig much in it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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">