Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1179
  • Last Modified:

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
0
service2001
Asked:
service2001
  • 4
  • 2
1 Solution
 
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
Independent Software Vendors: 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!

 
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

Featured Post

Independent Software Vendors: 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!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now