Tuesday, May 24, 2011

Validate file format(.xls or .xlsx) using File upload control using Javascript

Hi,

If you want the validate file type using the file upload control means like the wheather it is .doc or .xls or etc., using Javascript

fuUserList -- File upload control

var fuData = document.getElementById('<%=fuUserList.ClientID%>');
var fileUploadPath = fuData.value;

var extension = fileUploadPath.substring(fileUploadPath.lastIndexOf('.')
+ 1).toLowerCase();

if (extension == "xls" || extension == "xlsx")
{
return true; // Valid file type
}
else
{
document.getElementById('<%=divExcelError.ClientID%>').style.display = "block";
return false; // Not valid file type
}

No comments:

Post a Comment