Click here to Skip to main content
15,902,492 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have to upload images into DB using file up-loader. I have used the given below code, but it is not working. If I upload any pdf or doc file that also inserting into DB and the error message also displaying. I want to stop insertion if the file is not an image format. Help me to find a proper solution. Thank you.

ASPX:

ASP.NET
<asp:FileUpload ID="PhotoUpload1" runat="server" ForeColor="#999999" /><asp:RegularExpressionValidator ID="RegularExpressionValidator6" runat="server" ErrorMessage="*jpeg,gif,png" ControlToValidate="PhotoUpload1" ForeColor="Red" ValidationExpression=".*\.([gG][iI][fF]|[jJ][pP][gG]|[jJ][pP][eE][gG]|[bB][mM][pP])$"></asp:RegularExpressionValidator>
Posted
Comments
George Jonsson 8-Dec-14 2:16am    
Do you have some examples of strings you want to validate?
Is it just a filename with an extension?
Member 11042100 8-Dec-14 2:18am    
i want to validate only image files.
Sinisa Hajnal 8-Dec-14 2:33am    
It would be easier to check server side if PhotoUpload1.HasFile then GetFileExtension (or some such) - provide extension list and check.

What about tif, tiff and png files? Those are image files too.
Member 11042100 8-Dec-14 2:49am    
can you please post one sample code here!

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



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