Hi,
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="Upload" />
<script type="text/javascript">
function validateFileUpload(obj){
var fileName = new String();
var fileExtension = new String();
fileName = obj.value;
fileExtension = fileName.substr(fileName.length - 3, 3);
var validFileExtensions = new Array("jpg", "png", "gif");
var flag = false;
for(var index = 0; index < validFileExtensions.length; index++){
if(fileExtension.toLowerCase() == validFileExtensions[index].toString().toLowerCase()){
flag = true;
}
}
if(flag == false){
alert('Files with extension ".' + fileExtension.toUpperCase() + '" are not allowed.\n\nYou can upload the files with following extensions only:\n.jpg\n.png\n.gif\n');
return false;
}
else{
alert('File has valid extension.');
return true;
}
}
</script>
protected void Page_Load(object sender, EventArgs e)
{
FileUpload1.Attributes.Add("onchange", "return validateFileUpload(this);");
btnUpload.Attributes.Add("onclick", "return validateFileUpload(document.getElementById('" + FileUpload1.ClientID + "'));");
}