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).
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).
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 an uploaded file exceeds MaxFileSize or MaxFileCount, the ASPxUploadControl displays an error frame in Standard upload mode or an alert box in Advanced upload mode. In this case, the file fails validation (UploadedFile.IsValid, FileUploadCompleteEventArgs.IsValid, and [ASPxClientUploadControlFileUploadCompleteEventArgs.isValid] return false). Use UploadControlValidationSettings.MaxFileSizeErrorText and UploadControlValidationSettings.MaxFileCountErrorText to specify the error text.