Limit number of Files to be uploaded

7 posts, 1 answers
  1. chris
    chris avatar
    32 posts
    Member since:
    Jul 2011

    Posted 03 Jan 2012 Link to this post

    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
  2. Answer
    Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1266 posts

    Posted 03 Jan 2012 Link to this post

    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
  3. CHOON AIK
    CHOON AIK avatar
    7 posts
    Member since:
    Sep 2012

    Posted 22 Jun 2015 in reply to Dimitar Terziev Link to this post

    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" />

  4. Nencho
    Admin
    Nencho avatar
    1661 posts

    Posted 24 Jun 2015 Link to this post

    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
  5. Darryl
    Darryl avatar
    2 posts
    Member since:
    Nov 2012

    Posted 24 Oct Link to this post

    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?

  6. Darryl
    Darryl avatar
    2 posts
    Member since:
    Nov 2012

    Posted 24 Oct in reply to Darryl Link to this post

    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>
  7. Peter Milchev
    Admin
    Peter Milchev avatar
    290 posts

    Posted 27 Oct Link to this post

    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.
Back to Top