Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Upload > RadAsyncUpload Clear uploaded files

Not answered RadAsyncUpload Clear uploaded files

Feed from this thread
  • Fred Mare avatar

    Posted on May 21, 2010 (permalink)

    Hi

    I have 2 questions that I need some help with if possible.

    1)

    I have implemented the RadAsyncUpload conrol in my web application to allow a user to upload files to the server. I would like to clear the uplaoded file list above the select button and this uploaded files in Javascript. Is this possible?

    2)

    How do a person code for when a file already exists using the RadAsyncUpload conrol?

    Thank you
    Fred

    Reply

  • Genady Sergeev Genady Sergeev admin's avatar

    Posted on May 26, 2010 (permalink)

    Hello Fred Mare,

    With respect to your first question, the described behavior can be achieved  using the following code:

    <script type="text/javascript">
           function clientFileUploaded(sender, args) {
               var count = sender._getRowCount();
     
               if (count > 2) {
                   Array.removeAt(sender._uploadedFiles, 0);
                   sender.deleteFileInputAt(0);
                   sender.updateClientState();
               }
           }
            
       </script>
     
       <telerik:RadAsyncUpload runat="server" ID="RadAsyncUpload1" TargetFolder="~/Documents"
            OnClientFileUploaded="clientFileUploaded">
       </telerik:RadAsyncUpload>

    Regarding your second question, you can hook on the FileUploaded  server-side event of RadAsyncUpload and check whether the current file already exists. This can be done using the following code:

    void RadAsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
        {
            string fullPath = Server.MapPath(Path.Combine(RadAsyncUpload1.TargetFolder, e.File.GetName()));
     
            if (File.Exists(fullPath))
            {
                e.IsValid = false;
                e.File.SaveAs(Server.MapPath(
                    Path.Combine(RadAsyncUpload1.TargetFolder, e.File.GetNameWithoutExtension() + "1" + e.File.GetExtension())));
            }
        }

    If the file already exists, 1 is appended to the file name and the uploaded file is saved with the new name. Sample project demonstrating the approach is attached to this replay.

    Greetings,
    Genady Sergeev
    the Telerik team

    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 Public Issue Tracking system and vote to affect the priority of the items.
    Attached files

    Reply

  • Fred Mare avatar

    Posted on May 28, 2010 (permalink)

    Dear Genady

    Thank you for the help I appreciate it very much.

    Reply

  • Jesse Lawler avatar

    Posted on Oct 15, 2010 (permalink)

    I need to call a client-side function (NOT a RadAsyncUpload event handler) to remove all files from a RadAsyncUpload object.  I tried to adapt the code provided above into the following function, but I'm getting weird behavior.  Could you please tell me what is amiss?

            function ClearUploads() {
                var uploadObject = $find('<%= RadAsyncUpload1.ClientID %>');
                var uploadedFileCount = uploadObject._getRowCount() - 1;
                if (uploadedFileCount > 0) {
                    for (i = 0; i < uploadedFileCount; i++) {
                        Array.removeAt(uploadObject._uploadedFiles, i);
                        uploadObject.deleteFileInputAt(i);
                    }
                    uploadObject.updateClientState();
                }
            }

    Reply

  • Fred Mare avatar

    Posted on Oct 16, 2010 (permalink)

    Dear Jesse

    What behavior are you experiencing?

    Fred

    Reply

  • Jesse Lawler avatar

    Posted on Oct 16, 2010 (permalink)

    Right now, for example, if I upload 4 files into the RadAsynUpload control, then run the function below, it will delete the first two of the files, but leave the second 2 intact.  It's probably just my misunderstanding how the indexing of the uploaded files works... Any ideas?

    Reply

  • Fred Mare avatar

    Posted on Oct 17, 2010 (permalink)

    I think you right. If possible could you upload a little test app so I can test this concept from side?

    Fred

    Reply

  • Fred Mare avatar

    Posted on Oct 18, 2010 (permalink)

    Are you trying to delete the files from the target folder or the temporary folder?  

    Fred

    Reply

  • Jesse Lawler avatar

    Posted on Oct 18, 2010 (permalink)

    I'm trying to delete from the temporary folder.  Basically, if a user has started some uploading using this form, but not submitted the finalized form, I want to empty out the uploaded files after a certain length of time or under certain conditions.  

    Thanks!

    Reply

  • Fred Mare avatar

    Posted on Oct 18, 2010 (permalink)

    When I use your code I manage to remove the list of selected files from web page. But the file still remain in the temp folder. Are you experiencing the same?

    Fred

    Reply

  • Genady Sergeev Genady Sergeev admin's avatar

    Posted on Oct 21, 2010 (permalink)

    Hi guys,

    The files are going to be removed from the temporary folder after a few hours (the default is 4). You can tweak that time via the TemporaryFilesExpiration property that RadAsyncUpload provides. Also, the code worked fine on my side as well. Fred, could you please attach a sample aspx page that reproduces the problem so that we can take a look.

    Kind regards,
    Genady Sergeev
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Fred Mare avatar

    Posted on Oct 22, 2010 (permalink)

    Dear Genady

    This is an issue that Jesse reported. I thought I would see if I can help.

    Fred

     

    Reply

  • Jesse Lawler avatar

    Posted on Oct 22, 2010 (permalink)

    Hi there Genady --

    Sorry it took me a bit to reply.  I've created a super-simple example ASPX page which is still misbehaving for me.  I've come up with a workaround so this is not a pressing issue that requires a support ticket for me...  But I'll open one if that's the only way to get an ASPX file to you.  It won't let me attach code files in the form.  Please advise.

    (And thank you, Fred.)

    Jesse

    Reply

  • Genady Sergeev Genady Sergeev admin's avatar

    Posted on Oct 27, 2010 (permalink)

    Hello Jesse Lawler,

    Indeed, the only way to attach ASPX page is to open a support ticket. It would be very helpful If you specify the exact version of Telerik.Web.UI that you use. Thank you.

    Regards,
    Genady Sergeev
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Kartar avatar

    Posted on May 14, 2012 (permalink)

    Hi ,

    I am using this control in my project . Suppose i uploaded 2 files and now i am clicking on window close button and i want to clear both uploaded files from client side not from server side . I am not able to clear all files . Last file is not removed from the list . now if i open my pop up again last file name still apper with upload control.

    I am using below code at client side:

     

     

    var uploadedFileCount = uploadObject._uploadedFiles.length;

     

     

     

     

    if (uploadedFileCount > 0) {

     

     

     

    for (i = 0; i <uploadedFileCount; i++) {

     

    Array.removeAt(uploadObject._uploadedFiles, i);

    uploadObject.deleteFileInputAt(i);

    }

    uploadObject.updateClientState();

    }



    Please reply i need it very urgently . I think i am missing some index . please guide me.

    Reply

  • Posted on May 14, 2012 (permalink)

    Hello Kartar,

    Here is the following javascript which worked as expected in my end.
    JS:
    function DeleteFiles()
    {
     var upload = $find("<%= RadAsyncUpload1.ClientID %>");
     var inputs = upload.getUploadedFiles().length;
      for (i = 0; i <= inputs; i++)
     {
      upload.deleteFileInputAt(i);
     }
    }

    Thanks,
    Princy.

    Reply

  • Kartar avatar

    Posted on May 14, 2012 (permalink)

    Hi Princy ,

    Thanks for quick reply . I was doing same but it was not working when i debug it i got solution for it and i found below solutions :

    Solution 1:

    function DeleteFiles()
    {
     var upload = $find("<%= RadAsyncUpload1.ClientID %>");
     var inputs = upload.getUploadedFiles().length;
      for (i = 0; i <= inputs; i++)
     {
      upload.deleteFileInputAt(0);
     }
    }

    Solution 2:

    function DeleteFiles()
    {
     var upload = $find("<%= RadAsyncUpload1.ClientID %>");
     var inputs = upload.getUploadedFiles().length;
      for (i = inputs-1; i >=0; i--)
     {
      upload.deleteFileInputAt(i);
     }
    }

    Its working for me . Thanks once again!!!!!!

    Reply

  • Say Hello to Telerik's PivotGrid for ASP.NET AJAX, Silverlight, WPF and WinForms. Now packed with OLAP support.

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Upload > RadAsyncUpload Clear uploaded files
Related resources for "RadAsyncUpload Clear uploaded files"

ASP.NET Upload Features  |  Documentation  |  Demos  |  Step-by-step Tutorial  ]