Categories
Asp, Asp.net

File Upload Extension Check In ASP.NET With JQuery

File Upload Extension Check In ASP.NET With JQuery

Hi Guys, In this tutorial i will let you know about File Upload Extension Check In ASP.NET With JQuery or you can say how to validate File Upload Control To upload only certain types of files.Here i am validating file upload control with the help of JQuery.In my previous post i check the file upload extension with the help of code written in C#, JQuery is lightweight and and added a check at client side, means no processing at server side.

Design View:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
}
</style>
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function () {
$('#<%=FileUpload1.ClientID %>').change(function () {
var fileExtension = ['jpeg', 'jpg', 'png', 'gif', 'bmp'];
if ($.inArray($(this).val().split('.').pop().toLowerCase(), fileExtension) == -1) {
alert("Only Following Formats are Allowed .jpeg,.jpg,.png,.gif,.bmp");
}
})
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table align="center" cellpadding="0" cellspacing="0" class="auto-style1" style="width: 900px">
<tr>
<td>Image</td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>