Restricting uploading files based on its extension in EJ 1 ASP.NET MVC UploadBox

6 Mar 2017 / 1 minute to read

Allow Extension

Files are filtered before they are uploaded. You can select the files to be filtered by using browse button. The ExtensionsAllow property allows upload of the selected extensions only. You can give multiple extensions by using comma (,). The data type is string.

NOTE

Prepend dot (.) symbol with extension like “.pdf”.

The following steps explain the configuration of ExtensionsAllow property in UploadBox.

  1. In the VIEW page, add the below script to configure the UploadBox element.
  • cshtml
  • // In the CSHTML page, add UploadBox element.
    
    @Html.EJ().Uploadbox("uploadbox").SaveUrl("Uploadbox/Save").RemoveUrl("Uploadbox/Remove").ExtensionsAllow(".docx,.pdf")

    Deny Extension

    Files are filtered before they are uploaded. You can select the files to be filtered by using browse button. The ExtensionsDeny property denies upload of the selected extensions. You can give multiple extensions by using comma (,). The data type is string.

    NOTE

    Prepend dot (.) symbol with extension like “.pdf”.

    The following steps explain the configuration of ExtensionsDeny property in UploadBox

    1. In the VIEW page, add the below script to configure the UploadBox element.
  • cshtml
  • // In the CSHTML page, add UploadBox ox element.
    
    @Html.EJ().Uploadbox("uploadbox").SaveUrl("Uploadbox/Save").RemoveUrl("Uploadbox/Remove").ExtensionsDeny(".docx,.pdf")

    NOTE

    When ExtensionsDeny and ExtensionsAllow properties have same file extension, the extension will be allowed.