Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
tbl_extension
<table border="1" width="80%><br" mode="hold" />  <tr>
    <td>ID</td>
    <td>extension</td>
    <td>Class</td>
  </tr>
  <tr>
    <td>1</td>
    <td>.jpg</td>
    <td>image</td>
  </tr>
  <tr>
    <td>2</td>
    <td>.png</td>
    <td>image</td>
  </tr>
  <tr>
    <td>3</td>
    <td>.gif</td>
    <td>image</td>
  </tr>
  <tr>
    <td>4</td>
    <td>.bmp</td>
    <td>image</td>
  </tr>
  <tr>
    <td>5</td>
    <td>.avi</td>
    <td>video</td>
  </tr>
  <tr>
    <td>6</td>
    <td>.mp4</td>
    <td>video</td>
  </tr>
  <tr>
    <td>7</td>
    <td>.mp3</td>
    <td>audio</td>
  </tr>
  <tr>
    <td>8</td>
    <td>.wma</td>
    <td>audio</td>
  </tr>
</table>


Default.aspx
DropDownList:
ASP.NET
<asp:DropDownList ID="DropDownList1" runat="server">
     <asp:ListItem>image</asp:ListItem>
     <asp:ListItem>video</asp:ListItem>
     <asp:ListItem>audio</asp:ListItem>
</asp:DrpDownList>


file upload :
<asp:FileUpload ID="FileUpload1" runat="server" />


Upload Button :
ASP.NET
<asp:Button ID="Button1" runat="server" Text="Upload" />



Default.aspx.vb
notice:I also created a connection to DataBase with a vb class page.

I uploaded an image(1.jpg) but this code isn't working...
con.connecton()

con.query("select * from tbl_extension where Class='" & DropDownList1.SelectedItem.ToString & "' ")

While con.Reader.Read()
If FileUpload1.FileName Like "*" & con.Reader("extension").toString then

     FileUpload1.PostedFile.SaveAs("c:\test\")

     EndIf

End While

con.Reader.Close()






notice:in this example i select the same image but it is woking normaly !!!.

If FileUpload1.FileName Like "*.jpg" then

          FileUpload1.PostedFile.SaveAs("c:\test\")

EndIf
Posted
Updated 20-Sep-13 3:45am
v2
Comments
CodeBlack 20-Sep-13 9:48am    
what do you get as a value of con.Reader("extension").toString ?

Like is not a valid VB.NET operator.
It is a SQL comparison operator, but the place you are using it is definitely not a SQL query.
Comparison operator in VB is '='.
Moreover, logical AND/OR operators are not '&' and '|' in VB ; they are 'AndAlso' and 'OrElse'.
I'm even surprised you managed to compile the piece of code you've given to us.
 
Share this answer
 
v3
Comments
[no name] 20-Sep-13 10:04am    
Actually it is, http://msdn.microsoft.com/en-us/library/swf8kaxw.aspx
Nchantim 20-Sep-13 10:23am    
Yes, Like has been around in Vb.Net for eight years.
phil.o 20-Sep-13 10:18am    
OK, my bad ; I'll edit the solution. This explains also why I took the '&' for a logical operator.
It's been 10 years now I didn't write anything in VB, but I can't remember having used it once.
Like is a perfectly valid VB.Net operator

1) Have you tried checking the case?

If FileUpload1.FileName.ToUpper Like "*" & con.Reader("extension").toString.ToUpper then

2) Are you sure tbl_Extension entries start with a period?

3) Could you substitute an EndsWith ?

If FileUpload1.FileName.ToUpper.EndsWith(con.Reader("extension").toString.ToUpper) then
 
Share this answer
 
The problem was that i was saving the data type of the column (( Class )) as "" nChar(10) "" so it takes the rest of the digits as spaces .. i put it as "" nvarChar(10) "" and IT WORKED :D !!

The like operator worked normally but the problem was in the extension !
 
Share this answer
 

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


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900