Allowed File Count and Size

  • 2 minutes to read

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

Allowed Files Size

Use the following properties to set and get the maximum size of a file that end-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 Files Count

Use the following properties to manage the maximum number of files that end-users 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 will display 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 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 texts.