1

I want to filter the browse window for only .jpg files.

<asp:FileUpload ID="fileDocument" runat="server"></asp:FileUpload>

Here is the image :- enter image description here

here I want that it should only display .jpg file. How can I do this?

Blender
  • 289,723
  • 53
  • 439
  • 496
Rajesh Biswas
  • 242
  • 1
  • 2
  • 16
  • 2
    http://stackoverflow.com/questions/3521122/html-input-type-file-apply-a-filter possibble duplicate – Doan Cuong Apr 29 '13 at 07:31
  • 1
    http://stackoverflow.com/questions/2780191/how-to-restrict-file-type-in-fileupload-control possible duplicate – Pouki Apr 29 '13 at 07:31

3 Answers3

0

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

Community
  • 1
  • 1
Nomad101
  • 1,688
  • 11
  • 16
0

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>
Arif YILMAZ
  • 5,754
  • 26
  • 104
  • 189
0

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>