Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Saturday, 25 April 2015

To check file extensions while uploading

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);" />

Please provide your feedback in the comments section above. Please don't forget to follow.