upload only gif/jpg/bmp images

how to validate the image type in vb.net?

i want to restrict to the user to upload only gif/jpg/bmp images

what is the best way to restrict?

thanks
service2001Asked:
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.

service2001Author Commented:
i need the code to pupup alert message that, you are allowed to upload gif/jpg images.

is there any code can do that?
0
ryerrasCommented:
You can display a javascript alert message when the user clicks on a button to upload the image.

<input type="submit" name="Button1" value="Button" id="Button1"  onclick="javascript:alert('you are allowed to upload gif/jpg images.');" />

Now in your button click handler on the server, simply validate the extension of the file using the fileinfo classe's "Extension" property
0
service2001Author Commented:
can i have a complete code please?
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

ryerrasCommented:
You can also use System.IO.Path Class in .NET

string fileName = @"C:\mydir.old\myfile.ext";
string extension;

extension = Path.GetExtension(fileName);
0
service2001Author Commented:
but how do i check on client side?

0
service2001Author Commented:
if you have done similar, would you paste the code here for my reference? thank you!
0
nisarkhanCommented:
<TD align="right">
<asp:label id="lblUploadLogo" runat="server"></asp:label>
</TD>
<TD colSpan="2">
<INPUT id="fileupload1" style="WIDTH: 299px; HEIGHT: 22px" type="file" size="30" name="fileupload1"
runat="server">

<asp:image id="imgLogoFile" runat="server" Width="30px" Height="24px"></asp:image>
<asp:RegularExpressionValidator id="Regularexpressionvalidator1" runat="server" ErrorMessage="Select valid file *.gif or *.jpg or bmp file!"

ControlToValidate="fileupload1" ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))+(.gif|.bmp|.jpg)$"></asp:RegularExpressionValidator></TD>
</TR>
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.