New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial
Limit the Number of the Uploaded Files
Updated over 1 year ago
Common case is the need to limit the maximum number of files that can be uploaded. This article shows step by step how to create a custom limitation.
Limit the Number of the Uploaded Files
-
Add new RadCloudUpload control.
-
Set MultipleFileSelection property to true to enable Multi File Selection.
-
Handle OnClientFilesSelecting event.
ASPNET
<telerik:RadCloudUpload ID="RadCloudUpload1" runat="server" ProviderType="Azure" OnClientFilesSelecting="onClientFilesSelecting" MultipleFileSelection="Automatic">
</telerik:RadCloudUpload>
JavaScript
//Limit the number of the uploaded files.
function onClientFilesSelecting(sender, args) {
var uploadedFilesCount = sender.get_uploadedFiles().length;
var selectedFilesCount = args.get_count();
if (selectedFilesCount > 5 || (uploadedFilesCount + selectedFilesCount > 5)) {
args.set_cancel(true);
alert('You can upload up to 5 files.');
}
}