Home  »  Articles  »  ASP.Net  »

Validate to upload only image(.gif or .jpg) file

 Posted By : Manoranjan SahooPosted Date : 27/10/2010 07:31:50 AM Category : ASP.Net Points : 3

Some times we need to restrict user to upload only image type.

Now the query is how to achieve this?

use the below code to restrict user to upload only image file i.e. : .gif or .jpg file

<asp:FileUpload ID="fupload" height="25px" runat="server" />
<asp:RegularExpressionValidator id="REVfupload" runat="server" ErrorMessage="Upload only .jpg or .gif file." ValidationExpression="^.*\.(jpg|JPG|gif|GIF|jpeg|JPEG)$" ControlToValidate="fupload">


If you want to allow .png file then change validation expression like below :


Thank You.

No responses found for this thread. Be the first to respond this thread.
Post Reply
Login to post Response.