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

How to Remove selected file in AsyncUpload

12 Answers 738 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Nidhi
Top achievements
Rank 1
Nidhi asked on 04 Jul 2011, 02:34 PM
Hi,

I have an issue in the asyncupload. I am uploading a file and checking the file name through database that it is existing or not and i am doing this through the javascript pagemethod. But through the pagemethod i just want to remove the file on a particular condition.
Like 

function ToResetValidation(sender, eventArgs) {
            var FileName = eventArgs.get_fileName().split('.').reverse().slice(1).reverse().join('.');
            PageMethods.GetFileName(FileName, Onsucess);
                  }


 function Onsucess(result) {
            if (result == 1) {
                alert('This file is already exsist');
*********              // Here i have to remove the file from uploader on clientside  *******   CONDITION
                return false;
            }
        }


<telerik:RadAsyncUpload ID="RUImage"  OnClientDeleting="ToDeleteFile" runat="server"
                                            AllowedFileExtensions=".pdf,.doc,.docx" ControlObjectsVisibility="None" InputSize="35" Width="300px" style="float:left; margin-top:5px; "
                                            Font-Names="Arial" MaxFileSize="5242880" OnClientFileUploaded="ToResetValidation"
                                            AutoAddFileInputs="true" OnClientValidationFailed="validationFailed" MaxFileInputsCount="1"
                                            TabIndex="4" >
                                        </telerik:RadAsyncUpload>


Thanks
Manish

12 Answers, 1 is accepted

Sort by
0
Peter Filipov
Telerik team
answered on 06 Jul 2011, 03:13 PM
Hello Nidhi,

Please review the following sample code. Please cancel the upload when OnClientFileUploading event is fired.
<form id="form1" runat="server">
    <div>
        <telerik:RadScriptManager runat="server" ID="RadScriptManager"></telerik:RadScriptManager>
        <telerik:RadAsyncUpload runat="server" ID="RadAsyncUpload1" OnClientFileUploading="onClientFileUploading" MultipleFileSelection="Automatic"></telerik:RadAsyncUpload>
 </div>
    </form>
    <script type="text/javascript">
        function onClientFileUploading(sender, args) {
            var test = args.get_fileName();
            if(test.length > 10)
            sender._cancelUpload(args.get_row());
        }
    </script>


Greetings,
Peter Filipov
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Charlie
Top achievements
Rank 1
answered on 08 Jul 2011, 02:14 PM
Hi Peter,

When I used the sample code you provided I got the error:
Uncaught Error: Error calling method on NPObject.

Can you help with it?

Thanks,
Charlie
0
Peter Filipov
Telerik team
answered on 12 Jul 2011, 05:04 PM
Hello Charlie,

That functionality is not officially supported. When using IFrame/Silverlight to upload files with RadAsyncUpload it is possible to cancel the upload when the OnClientFileUploading event is fired. Please disable Flash module with the following sample code:
Telerik.Web.UI.RadAsyncUpload.Modules.Flash.isAvailable = function () { return false; };

That functionality will be implemented officially.

Kind regards,
Peter Filipov
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Charlie
Top achievements
Rank 1
answered on 13 Jul 2011, 05:01 PM
Hi Pete,

Yes that worked. 

What if I want to check file name BEFORE file is sent to the server? I use the code you provided on OnClientFileSelected event and got loads of error including Uncaught Error: Error calling method on NPObject.
Any Ideas?

Thanks,
Charlie
0
Peter Filipov
Telerik team
answered on 14 Jul 2011, 12:33 PM
Hello Charlie,

Please clarify which version of our controls and browser are you using? Could you please check which module are you using to upload files (right button click on the file input)?

Best wishes,
Peter Filipov
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Charlie
Top achievements
Rank 1
answered on 05 Aug 2011, 02:12 PM
Hi Peter,

Right I use sender._cancelUpload(args.get_row())in the OnClientFilesSelected event which caused the error.
But if I use it in the OnClientFileUploading event, the file will still be uploaded to server.

I know I can stop file uploading in the OnClientFilesSelected event, but inside this event I can not get the selected filename. Also it will cancel all files to be uploaded. What if I multi-select 3 files and just want to cancel one of them? OnClientFileSelected event doesn't support cancel function.

I am using version Q1 2011.

Please help.

Thanks,
Charlie
0
Peter Filipov
Telerik team
answered on 10 Aug 2011, 12:54 PM
Hi Charlie,

For the next service pack it will be possible to cancel the uploading event with every module FileApi/Silverligh/Flash/IFrame and the file is not going to be uploaded. In the OnClientFileSelected event handler it is not possible to use the _cancelUpload method.

Greetings,
Peter Filipov
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Ayaz
Top achievements
Rank 1
answered on 14 Mar 2013, 09:10 PM
Hi

with sender._cancelUpload(args.get_row()); we can cancel uploading of file, but files will be there in 

$find(RadAsyncUpload1).getUploadedFiles()

How to get canceled files or remove it from getUploadedFiles()?

Thanks
0
Plamen
Telerik team
answered on 18 Mar 2013, 08:38 AM
Hello,

Here is the code that should help you remove the canceled file:

function OnClientFileUploading(sender, args) {
 
               sender._cancelUpload(args.get_row());
               sender._updateCancelButton(args.get_row());
               $telerik.$(".ruRemove", args.get_row()).click();
           }

Hope this will be helpful.
Greetings,
Plamen
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
Ayaz
Top achievements
Rank 1
answered on 19 Mar 2013, 02:48 PM
Thanks Plamen,

appreciate your help.

In case of Multiple file selection I moved that code in OnClientFileUploaded(sender, args) event.  and it;s working fine.
Thanks
0
Joe
Top achievements
Rank 1
answered on 23 Dec 2015, 04:11 PM

I modified it to behave only when ".ruCancel" is clicked."  I'm not sure if this is exactly right, but it seems to work.  

Please correct as necessary.

window.onClientFileUploading = function (sender, args) {
    $(".ruCancel", args.get_row()).click(function () {
        sender._cancelUpload(args.get_row());
        sender._updateCancelButton(args.get_row());
        $(".ruRemove", args.get_row()).click();
    });
}

0
Plamen
Telerik team
answered on 24 Dec 2015, 06:05 AM
Hi,

The code seems correct. If you experience some issues let me know.

Regards,
Plamen
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
Tags
AsyncUpload
Asked by
Nidhi
Top achievements
Rank 1
Answers by
Peter Filipov
Telerik team
Charlie
Top achievements
Rank 1
Ayaz
Top achievements
Rank 1
Plamen
Telerik team
Joe
Top achievements
Rank 1
Share this question
or