I want to filter the browse window for only .jpg files.
<asp:FileUpload ID="fileDocument" runat="server"></asp:FileUpload>
Here is the image :-
here I want that it should only display .jpg file. How can I do this?
I want to filter the browse window for only .jpg files.
<asp:FileUpload ID="fileDocument" runat="server"></asp:FileUpload>
Here is the image :-
here I want that it should only display .jpg file. How can I do this?
take a look at this:
File Upload with RegularExpressionValidator not working with Firefox only IE
However I believe exactly what you want to do may not be possible with the library you are using, you could try a different javascript library to do the file select.
Take a look at this: http://www.queness.com/post/11434/7-javascript-ajax-file-upload-plugins
I used RegularExpressionValidator before.
<asp:RegularExpressionValidator ID="validator_fileupload_extension" runat="server"
ControlToValidate="FileUpload1"
ErrorMessage="Images are allowed"
Text="*"
ValidationExpression="^.*\.(jpg|JPG|jpeg|JPEG)$">
</asp:RegularExpressionValidator>
Add this script in the head section of the aspx page.
<script type ="text/javascript">
var validFilesTypes=["bmp","gif","png","jpg","jpeg","doc","xls"];
function ValidateFile()
{
var file = document.getElementById("<%=FileUpload1.ClientID%>");
var path = file.value;
var ext=path.substring(path.lastIndexOf(".")+1,path.length).toLowerCase();
var isValidFile = false;
for (var i=0; i<validFilesTypes.length; i++)
{
if (ext==validFilesTypes[i])
{
break;
}
}
return isValidFile;
}
</script>