This is a migrated thread and some comments may be shown as answers.

Limit number of Files to be uploaded

6 Answers 1064 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
chris
Top achievements
Rank 1
chris asked on 03 Jan 2012, 05:25 PM
Hello everyone,

I see that there is a way to limit the number of file inputs with the RadAsyncUpload control but what I am trying to do is limit the user to only be able to upload 5 files. Is there a settle that will limit the user to only upload a set number of files?

-Chris

6 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar Terziev
Telerik team
answered on 03 Jan 2012, 05:32 PM
Hi Chris,

You could limit the number of the uploaded files using the MaxFileInputsCount property of the RadAsyncUpload. In your case you should set it to 5.

All the best,
Dimitar Terziev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
CHOON AIK
Top achievements
Rank 1
answered on 23 Jun 2015, 03:35 AM

Drag  and Drop is giving javascript error when "MaxFileInputsCount" property is set.

 Below is my design,

<telerik:RadAsyncUpload runat="server" ID="rauUpload" 
                    ChunkSize="1048576" InputSize="60" DropZones="#DropZone1" 
                    MaxFileInputsCount="5" MaxFileSize="2000000000" PostbackTriggers="btnUpload" />

0
Nencho
Telerik team
answered on 24 Jun 2015, 11:21 AM
Hello Choon,

I am afraid that I was unable to replicate the mentioned javscript error, using the provided code-snippet. Could you please specify what exactly is the error and what is the version of our controls that you are currently using?


Regards,
Nencho
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Darryl
Top achievements
Rank 1
answered on 24 Oct 2017, 06:17 PM

I am not able to replicate that, but my QA found a different issue.

While upload file count is limited to 5, when using the select button, I am still able to drag unlimited files to upload.

Is there a way to fix this drag/drop limit issue?

0
Darryl
Top achievements
Rank 1
answered on 24 Oct 2017, 08:23 PM

Here was my solution:

I added the corresponding parameters, to the upload control:

OnClientFileUploaded="Rad_OnClientFileUploaded" 

OnClientFileUploadRemoved="Rad_OnClientFileRemoved"

 

<telerik:RadCodeBlock ID="rad_block" runat="server">
    <script type="text/javascript">
        function Rad_OnClientFileUploaded(sender, e) {
            if (sender._uploadedFiles.length > sender._maxFileCount) {
                alert('File discarded! Exceeds max file limit of ' + sender._maxFileCount);
                sender.deleteFileInputAt(1);
                $(sender._element).find('input.ruBrowse').hide();
            }
        }
 
        function Rad_OnClientFileRemoved(sender, e) {
            $(sender._element).find('input.ruBrowse').show();
        }
    </script>
</telerik:RadCodeBlock>
0
Peter Milchev
Telerik team
answered on 27 Oct 2017, 12:23 PM
Hello Darryl,

I would suggest you try the OnClientFilesSelected event which would prevent the unnecessary upload of files.

Please find attached a sample project implementing the suggested approach. To run the project, the Telerik assemblies for .NET 4.5 should be added to the Bin folder.

function OnClientFilesSelected(sender, args) {
    var selector = sender.get_renderMode() == 2 ? '.ruInputs .ruFileLI' : '.ruInputs .ruUploadProgress'; // render mode 2 is Lightweight
    if (args.get_count() + $telerik.$(selector, sender.get_element()).length > sender.get_maxFileCount()) {
        args.set_cancel(true);
        // alert user that the maxFile limit is exceed
    }
}

The additional checks are for the case where a upload is ongoing.

Regards,
Peter Milchev
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
AsyncUpload
Asked by
chris
Top achievements
Rank 1
Answers by
Dimitar Terziev
Telerik team
CHOON AIK
Top achievements
Rank 1
Nencho
Telerik team
Darryl
Top achievements
Rank 1
Peter Milchev
Telerik team
Share this question
or