Hi,
You can't validate file on File Open Dialog in Asp.Net but you can validate file after selecting file from dialog.
Following are code to verify uploaded file is valid or not.
Javscript
<script type="text/javascript" language="javascript">
function validate() {
var uploadcontrol = document.getElementById('<%=FileUpload1.ClientID%>').value;
var reg = /^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))+(.doc|.docx|.DOC|.DOCX)$/;
if (uploadcontrol.length > 0)
{
if (reg.test(uploadcontrol))
{
return true;
}
else
{
alert("Only .doc, docx files are allowed!");
return false;
}
}
}
</script>
HTML
<asp:fileupload id="FileUpload1" runat="server" xmlns:asp="#unknown" />
<asp:button id="Button1" runat="server" text="Button" onclientclick="return validate();" xmlns:asp="#unknown" />
Thanks,
Imdadhusen