javascript:
var validFilesTypes = ["xls", "xlsx"]; function CheckExtension(file) { /*global document: false */ var filePath = file.value; var ext = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase(); var isValidFile = false; for (var i = 0; i < validFilesTypes.length; i++) { if (ext == validFilesTypes[i]) { isValidFile = true; break; } } if (!isValidFile) { file.value = null; alert("Invalid File. Valid extensions are:\n\n" + validFilesTypes.join(", ")); file.value=""; } return isValidFile; }
aspx page:
<asp:FileUpload ID="fuFile" runat="server" onchange="return CheckExtension(this);" />