RadAsyncUpload Clear uploaded files

17 posts, 0 answers
  1. Fred Mare
    Fred Mare avatar
    36 posts
    Member since:
    Dec 2009

    Posted 21 May 2010 Link to this post

    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

  2. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1539 posts
    Member since:
    Sep 2012

    Posted 26 May 2010 Link to this post

    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.

  3. Fred Mare
    Fred Mare avatar
    36 posts
    Member since:
    Dec 2009

    Posted 28 May 2010 Link to this post

    Dear Genady

    Thank you for the help I appreciate it very much.

  4. Jesse Lawler
    Jesse Lawler avatar
    46 posts
    Member since:
    Apr 2010

    Posted 15 Oct 2010 Link to this post

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

  5. Fred Mare
    Fred Mare avatar
    36 posts
    Member since:
    Dec 2009

    Posted 16 Oct 2010 Link to this post

    Dear Jesse

    What behavior are you experiencing?

    Fred

  6. Jesse Lawler
    Jesse Lawler avatar
    46 posts
    Member since:
    Apr 2010

    Posted 16 Oct 2010 Link to this post

    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?

  7. Fred Mare
    Fred Mare avatar
    36 posts
    Member since:
    Dec 2009

    Posted 17 Oct 2010 Link to this post

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

    Fred

  8. Fred Mare
    Fred Mare avatar
    36 posts
    Member since:
    Dec 2009

    Posted 18 Oct 2010 Link to this post

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

    Fred

  9. Jesse Lawler
    Jesse Lawler avatar
    46 posts
    Member since:
    Apr 2010

    Posted 18 Oct 2010 Link to this post

    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!

  10. Fred Mare
    Fred Mare avatar
    36 posts
    Member since:
    Dec 2009

    Posted 18 Oct 2010 Link to this post

    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

  11. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1539 posts
    Member since:
    Sep 2012

    Posted 21 Oct 2010 Link to this post

    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

  12. Fred Mare
    Fred Mare avatar
    36 posts
    Member since:
    Dec 2009

    Posted 22 Oct 2010 Link to this post

    Dear Genady

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

    Fred

     

  13. Jesse Lawler
    Jesse Lawler avatar
    46 posts
    Member since:
    Apr 2010

    Posted 22 Oct 2010 Link to this post

    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

  14. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1539 posts
    Member since:
    Sep 2012

    Posted 27 Oct 2010 Link to this post

    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

  15. Kartar
    Kartar avatar
    2 posts
    Member since:
    May 2012

    Posted 14 May 2012 Link to this post

    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.

  16. Princy
    Princy avatar
    16686 posts
    Member since:
    Mar 2007

    Posted 14 May 2012 Link to this post

    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.

  17. Kartar
    Kartar avatar
    2 posts
    Member since:
    May 2012

    Posted 14 May 2012 Link to this post

    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!!!!!!

Back to Top