Filter file extension using FileUpload

I am writing an asp.net web application that uses the FileUpload control.

Currently, this particular FileUpload control expects only .zip or .gz file types. If the wrong file type is loaded, an error message is displayed to the user. This functionality has already been implemented.

What I want to do is filter out the visible file types that the user sees when he clicks on “view”.

You may have seen a file open dialog box similar to the following.
enter image description here

I circled the area representing the file extension filter.

This is such a common feature that I expected it to be built into the current FileUpload control, but after some searching on the Internet I found a few posts that say this is not possible.

These positions have been since 2009, more than 2 years ago.

Now, my question is: does the current version of Asp.Net 4.0 support this function ?, and if not, do you know of any simple solution to get the necessary functions.

I would like to point out again that I can check if the user selects a supported file type. All I'm looking for is a cosmetic change that filters out unnecessary file types in the open file dialog.

+8
c # file-upload
source share
5 answers

I believe this is not possible. The file type filter in the browser is not controlled by asp.net. This is the functionality of the browser.

This question has already been asked in stackoverflow.Please filter the file type using file upload control

+5
source share

You can try the code below.

 <asp:FileUpload ID="UploadFile" accept="image/*" multiple="false" runat="server" BorderStyle="None" /> 

It works with modern browsers.

Remember to check the extensions using the code for the procedures.

+12
source share

To select images in the file upload control.

hope this helps you

 asp:RegularExpressionValidator ID="rexp" runat="server" ControlToValidate="fupProduct" ErrorMessage="Only .gif, .jpg, .png, .tiff and .jpeg" ValidationExpression="(.*\.([Gg][Ii][Ff])|.*\.([Jj][Pp][Gg])|.*\.([Bb][Mm][Pp])|.*\.([pP][nN][gG])|.*\.([tT][iI][iI][fF])$)"></asp:RegularExpressionValidator 
+5
source share

you can create confirmation of the file extension using the ASP.NET FileUpload control

I believe you can make that decision

Check file extension for ASP.NET file system management

0
source share

This is possible on the client side! But don't forget to do server side validation.

These two links show this: http://aspalliance.com/1614_Adding_Filter_Action_to_FileUpload_Control_of_ASPNET_20.all http://www.codeshode.com/2011/07/validate-file-extension-for-aspnet.html

0
source share

All Articles