How to Remove selected file in AsyncUpload

13 posts, 0 answers
  1. Nidhi
    Nidhi avatar
    23 posts
    Member since:
    Dec 2010

    Posted 04 Jul 2011 Link to this post

    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
  2. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 06 Jul 2011 Link to this post

    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!

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Charlie
    Charlie avatar
    8 posts
    Member since:
    Jul 2011

    Posted 08 Jul 2011 Link to this post

    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
  5. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 12 Jul 2011 Link to this post

    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!

  6. Charlie
    Charlie avatar
    8 posts
    Member since:
    Jul 2011

    Posted 13 Jul 2011 Link to this post

    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
  7. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 14 Jul 2011 Link to this post

    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!

  8. Charlie
    Charlie avatar
    8 posts
    Member since:
    Jul 2011

    Posted 05 Aug 2011 Link to this post

    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
  9. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 10 Aug 2011 Link to this post

    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.

  10. Ayaz
    Ayaz avatar
    2 posts
    Member since:
    Dec 2011

    Posted 14 Mar 2013 Link to this post

    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
  11. Plamen
    Admin
    Plamen avatar
    2733 posts

    Posted 18 Mar 2013 Link to this post

    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.
  12. Ayaz
    Ayaz avatar
    2 posts
    Member since:
    Dec 2011

    Posted 19 Mar 2013 Link to this post

    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
  13. Joe
    Joe avatar
    3 posts
    Member since:
    Dec 2015

    Posted 23 Dec 2015 in reply to Plamen Link to this post

    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();
        });
    }

  14. Plamen
    Admin
    Plamen avatar
    2733 posts

    Posted 24 Dec 2015 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017