Skip to main content

Allowed File Count and Size

  • 2 minutes to read

ASPxUploadControl allows you to validate the number of uploaded files and their maximum size.

Allowed File Size

Use the following properties to set and get the maximum size of a file that users can upload to the server.

  • UploadControlValidationSettings.MaxFileSize - Specifies the maximum file size (server side).

    <dxuc:ASPxUploadControl 
        ...
        <ValidationSettings 
            MaxFileSize="300000" 
        ...
        </ValidationSettings>
    </dxuc:ASPxUploadControl>
    
  • ASPxClientUploadControlValidationSettings.maxFileSize - Returns the maximum file size (client side).

    function getDetailsErrorInfoHtml(e) {
        var html = "";
        html += getDetailsErrorInfoHtmlByErrorType(e, ASPxClientUploadControlValidationErrorTypeConsts.MaxFileSizeExceeded,
            "These files exceed the allowed file size (the maximum file size is {0} bytes):<br /><ul>{1}</ul><br />",
            e.validationSettings.maxFileSize, true);
        ...
        return html;
     }
    

Allowed File Count

Use the following properties to manage the maximum number of files that a user can simultaneously upload to the server using ASPxUploadControl.

  • UploadControlValidationSettings.MaxFileCount - Specifies the maximum file count (server side).

    <dxuc:ASPxUploadControl 
        ...
        <ValidationSettings 
            MaxFileCount="10" 
        ...
        </ValidationSettings>
    </dxuc:ASPxUploadControl>
    
  • ASPxClientUploadControlValidationSettings.maxFileCount - Gets the maximum file count (client side).

    function getDetailsErrorInfoHtml(e) {
        var html = "";
        html += getDetailsErrorInfoHtmlByErrorType(e, ASPxClientUploadControlValidationErrorTypeConsts.MaxFileCountExceeded,
            "These files exceed the allowed file count (the maximum file count is {0}):<br /><ul>{1}</ul><br />",
            e.validationSettings.maxFileCount);
        ...
        return html;
     }
    

If the uploaded file exceeds the MaxFileSize or MaxFileCount property values, then ASPxUploadControl displays an error frame or alert box when the control operates in Standard or Advanced upload modes, respectively. In this case, ASPxUploadControl considers that the uploaded file has failed validation (the ASPxUploadControl.IsValid, FileUploadCompleteEventArgs.IsValid and ASPxClientUploadControlFileUploadCompleteEventArgs.isValid property values are false). Use the UploadControlValidationSettings.MaxFileSizeErrorText and UploadControlValidationSettings.MaxFileCountErrorText properties to specify error text.