0

I want to provent few extensions to load in FilUpload control. I have review few references

https://forums.asp.net/t/1051895.aspx?Fileupload+allow+only+jpg+gif+and+png

ASP.NET - Limit file upload available file types

But all are related to "which extensions should be allowed". But I need "which extensions should not allowed".

Can anybody please suggest me regular expression or any other way? I don't want to check manually while submiting.

I have read this example which regular expression about which files to allow. But I need ValidationExpression which doesn't allow some extension. I have list of extension which should not allowed. Can anybody suggest me ValidationExpression of it?

<asp:RegularExpressionValidator ID="uplValidator" runat="server" ControlToValidate="FileUpload1"
ErrorMessage=".mp3, .mp4 & wma formats are allowed" 
ValidationExpression="(.+\.([Mm][Pp][3])|.+\.([Mm][Pp][4])|.+\.([Ww][Mm][Aa]))"></asp:RegularExpressionValidator>
Community
  • 1
  • 1
Nanji Mange
  • 2,155
  • 4
  • 29
  • 63
  • 1
    Write the validate regular expression to disallow the extensions you don't want. – Allan S. Hansen Jan 03 '17 at 07:03
  • @AshishSrivastava no. they are not allow. I have just given example. I have opposite situation. I want `ValidationExpression` which doesn't allow .mp3, .mp4 & wma. Can you please guide me? – Nanji Mange Jan 03 '17 at 07:16
  • Ohk. Have a look [here](http://stackoverflow.com/a/11789389/5588347). So in Harish answer, why don't you try something like this: `if (reg.test(uploadcontrol) == true)` ? That's not actually a well solution but still it should work. – StackUseR Jan 03 '17 at 07:22
  • @AshishSrivastava I don't want any manual code(no event like button click). Is there any ValidationExpression that I can set in `RegularExpressionValidator`? If so, please suggest. – Nanji Mange Jan 03 '17 at 07:25
  • 1
    You can try this Validation Expression: http://stackoverflow.com/questions/23178316/regular-expression-for-excluding-file-types-exe-and-js – Willy David Jr Jan 03 '17 at 07:37

1 Answers1

0

You can use the HTML 5 accept attribute.

<asp:FileUpload ID="FileUpload1" runat="server" accept="video/*" />

You can still select all file types, but for most users this will be sufficient. And you still need to check the file type server-side, same as with RegularExpressionValidators.

Read more

VDWWD
  • 35,079
  • 22
  • 62
  • 79