sender.deleteFileInputAt();

7 posts, 0 answers
  1. Tan
    Tan avatar
    23 posts
    Member since:
    Jan 2012

    Posted 24 Apr 2012 Link to this post

    if i upload 2 file, and add second file and fileName is same i delete it using
         sender.deleteFileInputAt(sender.getUploadedFiles().length);


    It look like delete, but it didn't really delete..

        RadAsyncUpload1.UploadedFiles.Count , it still get 2
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 24 Apr 2012 Link to this post

    Hello Tan,

    Try the following javascript in OnClientFilesUploaded event.
    JS:
    function OnClientFilesUploaded(sender, args)
    {
     if (sender.getUploadedFiles().length != 1)
     {
      if (sender.getUploadedFiles()[0] == sender.getUploadedFiles()[1])
      {
       sender.deleteFileInputAt(sender.getUploadedFiles().length - 1);
      }
     }
    }

    Thanks,
    Shinu.
  3. Tan
    Tan avatar
    23 posts
    Member since:
    Jan 2012

    Posted 24 Apr 2012 Link to this post

    To

    Thanks, i fix it using onClientFilesUploaded for automatically remove duplicate same file name while uploading.Here is the code for sharing

    function onclientFileUploaded(sender, eventArgs) {
         var upload = $find("<%= RadAsyncUpload1.ClientID %>");
         var inputs = upload.getUploadedFiles();

        for (i = inputs.length - 1; i >= 0; i--) {
            var countSame = 0;
            for(z = inputs.length - 1;z >=0; z--){
                if (inputs[i]== inputs[z]) {
                   countSame++;
                   if(countSame>1)
                       sender.deleteFileInputAt(z);
                   var inputs = upload.getUploadedFiles();
                }
            }
        }
    }


    From Tan
  4. Yi Ling
    Yi Ling avatar
    7 posts
    Member since:
    Oct 2010

    Posted 04 May 2012 Link to this post

    Hi Shinu,

    I have the same issue.  Your code works fine if MaxFileSize is not specify in the code.
    I specify MaxFileSize=2MB in my code and upload files by the steps below:
    (1) a good file
    (2) a too large file - which exceeds 2mb
    (3) (1) 's file again

    and then (1) and (3) are both on the list.

    It seems whenever i upload a too large file, the sender.deleteFileInputAt() is not working.

    Could you help?

    Thanks!

    Joan
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 08 May 2012 Link to this post

    Hi Joan,

    Try the following JavaScript.

    ASPX:
    <telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server" MaxFileSize="5000" OnClientFilesUploaded="OnClientFilesUploaded" >
    </telerik:RadAsyncUpload>

    JS:
    <script type="text/javascript">
      function OnClientFilesUploaded(sender, args)
        {
            var upload = $find("<%= RadAsyncUpload1.ClientID %>");
            var inputs = upload.getUploadedFiles();
            var count = upload.getInvalidFiles().length + upload.getUploadedFiles().length;
            for (i = inputs.length - 2; i >= 0; i--)
              {
                if (inputs[i] == inputs[inputs.length - 1])
                 {
                        sender.deleteFileInputAt(count - 1);
                        break;
                 }
              }
        }
    </script>

    Hope this helps.

    Thanks,
    Shinu.
  6. Greg
    Greg avatar
    2 posts
    Member since:
    Feb 2009

    Posted 08 May 2012 Link to this post

    Hi Shinu,

    I tried your code but got the exception(Please refer to the screenshot below).  The telerik version we are using is 2011.1.519.35.  Is there any workaround if I have to use this version's telerik?

    Thanks!

    Joan
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 09 May 2012 Link to this post

    Hello Greg,

    I also observed the same behavior in the version 2011.1.519.35. Please try upgrading to the latest version.

    Thanks,
    Shinu.
Back to Top