Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Member
16 Points
12 Posts
Feb 10, 2008 07:53 PM|LINK
WoW, Egypt Winnnnnnnn,[:D][:D] and I just found the solution for that problem try this if you want ___________________________
<script language="javascript"> function ValidateFile(source, args) { try { var fileAndPath= document.getElementById(source.controltovalidate).value; var lastPathDelimiter=fileAndPath.lastIndexOf("\\"); var fileNameOnly=fileAndPath.substring(lastPathDelimiter+1); var file_extDelimiter=fileNameOnly.lastIndexOf("."); var file_ext=fileNameOnly.substring(file_extDelimiter+1).toLowerCase(); if(file_ext!="jpg") { args.IsValid = false; if(file_ext!="gif") args.IsValid = false; if(file_ext!="png") { args.IsValid = false; return; } } }catch(err) { txt="There was an error on this page.\n\n"; txt+="Error description: " + err.description + "\n\n"; txt+="Click OK to continue.\n\n"; txt+=document.getElementById(source.controltovalidate).value; alert(txt); } args.IsValid = true; } </script> <asp:FileUpload ID="FileUpload1" runat="server" /> <asp:CustomValidator ID="CustomValidator1" ClientValidationFunction="ValidateFile" runat="server" ControlToValidate="FileUpload1" Display="dynamic" ErrorMessage="images only "> </asp:CustomValidator>
please post comments if there any comment,I'm not sure about it yet,
Thank you
moud_gersy
Member
16 Points
12 Posts
Re: Fileupload: allow only .jpg .gif and .png
Feb 10, 2008 07:53 PM|LINK
WoW, Egypt Winnnnnnnn,[:D][:D]
and I just found the solution for that problem
try this if you want
___________________________
<script language="javascript"> function ValidateFile(source, args) { try { var fileAndPath= document.getElementById(source.controltovalidate).value; var lastPathDelimiter=fileAndPath.lastIndexOf("\\"); var fileNameOnly=fileAndPath.substring(lastPathDelimiter+1); var file_extDelimiter=fileNameOnly.lastIndexOf("."); var file_ext=fileNameOnly.substring(file_extDelimiter+1).toLowerCase(); if(file_ext!="jpg") { args.IsValid = false; if(file_ext!="gif") args.IsValid = false; if(file_ext!="png") { args.IsValid = false; return; } } }catch(err) { txt="There was an error on this page.\n\n"; txt+="Error description: " + err.description + "\n\n"; txt+="Click OK to continue.\n\n"; txt+=document.getElementById(source.controltovalidate).value; alert(txt); } args.IsValid = true; } </script> <asp:FileUpload ID="FileUpload1" runat="server" /> <asp:CustomValidator ID="CustomValidator1" ClientValidationFunction="ValidateFile" runat="server" ControlToValidate="FileUpload1" Display="dynamic" ErrorMessage="images only "> </asp:CustomValidator>____________________________
please post comments if there any comment,I'm not sure about it yet,
Thank you