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

Problem on get invalidFile ID to remove

2 Answers 90 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Tan
Top achievements
Rank 1
Tan asked on 13 Feb 2012, 11:48 AM
To,
Problem: Unabled get Invalid file index
to remove the invalid file by upload.deleteFileInputAt(i); since upload.getUploadedFiles(); only get valid file index.



<telerik:RadAsyncUpload runat="server" ID="RadAsyncUpload1"
                        MultipleFileSelection="Automatic" AllowedFileExtensions=".sql" MaxFileSize="1000000"
                        OnClientValidationFailed="DeleteInvalidFiles">
</telerik:RadAsyncUpload>

function DeleteInvalidFiles() {
            var upload = $find("<%= RadAsyncUpload1.ClientID %>");
            var inputs = upload.getUploadedFiles(); //Get Valid File only

            for (i = inputs.length - 1; i >= 0; i--) {
                alert(inputs[i].value);
                if (!upload.isExtensionValid(inputs[i].value))
                    upload.deleteFileInputAt(i);
            }
}

Thks
From Tan;

2 Answers, 1 is accepted

Sort by
0
Tan
Top achievements
Rank 1
answered on 14 Feb 2012, 03:47 AM
Hi,

i have use other idea to solve this, this is main code to share

sender.deleteFileInputAt(sender.getUploadedFiles().length);


From tan
0
Bozhidar
Telerik team
answered on 14 Feb 2012, 01:22 PM
Hello Louis,

Here is a sample function that you can use to delete all invalid files:
function deleteInvalids() {
    var upload = $find("<%= RadAsyncUpload1.ClientID %>");
 
    var indexes = [];
    $telerik.$(".ruUploadSuccess, .ruUploadFailure", upload.get_element()).each(function(index) {
        if ($telerik.$(this).hasClass('ruUploadFailure')) {
            indexes.push(index);
        }
    });
 
    while(indexes.length) {
        upload.deleteFileInputAt(indexes.pop());
    }
}

The method first goes through all uploaded files and adds the indexes of the invalid ones to an array. Then it goes through the array and deletes these files from the Upload.
 
Kind regards,
Bozhidar
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
AsyncUpload
Asked by
Tan
Top achievements
Rank 1
Answers by
Tan
Top achievements
Rank 1
Bozhidar
Telerik team
Share this question
or