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

sender.deleteFileInputAt();

6 Answers 190 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Tan
Top achievements
Rank 1
Tan asked on 24 Apr 2012, 12:22 PM
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

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 24 Apr 2012, 01:51 PM
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.
0
Tan
Top achievements
Rank 1
answered on 25 Apr 2012, 04:05 AM
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
0
Yi Ling
Top achievements
Rank 1
answered on 04 May 2012, 07:33 PM
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
0
Shinu
Top achievements
Rank 2
answered on 08 May 2012, 07:34 AM
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.
0
Greg
Top achievements
Rank 1
answered on 08 May 2012, 07:15 PM
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
0
Shinu
Top achievements
Rank 2
answered on 09 May 2012, 05:04 AM
Hello Greg,

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

Thanks,
Shinu.
Tags
AsyncUpload
Asked by
Tan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Tan
Top achievements
Rank 1
Yi Ling
Top achievements
Rank 1
Greg
Top achievements
Rank 1
Share this question
or