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

Avoiding Multiple File Selection

1 Answer 136 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Alp
Top achievements
Rank 1
Alp asked on 01 Aug 2013, 08:16 AM
Hi,

I am trying to avoid same file being selected more than one time. I have seen posts and replies such as
http://www.telerik.com/community/forums/aspnet-ajax/async-upload/avoid-duplicate-in-asyncupload-multiple-drag-and-drop.aspx
but when multiple file is selected (not drag/drop but selection from file dialog) all those functions are failing. Mostly, they miss the duplicate item at index 0. I have tried many other ways but could not figure out a solid and reliable way to achieve this.

Please note that I am also handling the file removed event and do some external stuff there, and I either need to find a way for one the scenarios below: 

* catch and cancel duplicates when file is selected (before uploading etc.), in which case I do not need the file removed handler (since file was not actually selected, it was cancelled) 

or

* catch duplicates at files uploaded event, and remove them from file list, properly calling file removed event

When single file is selected, previously suggested functions work fine, but when 6-8 files selected, problems show up.

Please advise.

Thanks.

1 Answer, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 06 Aug 2013, 08:27 AM
Hi Alp,

I would suggest you to perform file duplication check in OnClientFileUploading event:
function OnClientFileUploading(sender, args) {
    var fileName = args.get_fileName();
     
    for (var i = 0; i < sender.getUploadedFiles().length; i++) {
        if (sender.getUploadedFiles()[i] === fileName) {
            console.log('duplicated' + fileName);
            args.set_cancel(true);
            sender.deleteFileInputAt(sender.getUploadedFiles().length);
            $(".ErrorHolder").append(fileName + "duplicate file name have been remove automatically.<br/>").fadeIn("slow");
        }
         
    }
}

    <telerik:RadAsyncUpload
        ID="RadAsyncUpload1"
        OnClientFileUploading="OnClientFileUploading"
        MultipleFileSelection="Automatic"
        TargetFolder="~/Uploads"
        runat="server">
    </telerik:RadAsyncUpload>
<div class="ErrorHolder" style="background-color:red"></div>

This validation should be working with both Single and Multiple files selection.

Regards,
Hristo Valyavicharski
Telerik
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 the blog feed now.
Tags
AsyncUpload
Asked by
Alp
Top achievements
Rank 1
Answers by
Hristo Valyavicharski
Telerik team
Share this question
or