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

RadAsyncUpload Clear uploaded files

16 Answers 1996 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Fred Mare
Top achievements
Rank 1
Fred Mare asked on 21 May 2010, 03:49 PM

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

16 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 26 May 2010, 01:45 PM
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.
0
Fred Mare
Top achievements
Rank 1
answered on 28 May 2010, 07:58 AM
Dear Genady

Thank you for the help I appreciate it very much.
0
Jesse Lawler
Top achievements
Rank 1
answered on 16 Oct 2010, 03:11 AM
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();
            }
        }
0
Fred Mare
Top achievements
Rank 1
answered on 16 Oct 2010, 10:22 AM

Dear Jesse

What behavior are you experiencing?

Fred

0
Jesse Lawler
Top achievements
Rank 1
answered on 16 Oct 2010, 04:50 PM
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?
0
Fred Mare
Top achievements
Rank 1
answered on 17 Oct 2010, 10:17 AM
I think you right. If possible could you upload a little test app so I can test this concept from side?

Fred
0
Fred Mare
Top achievements
Rank 1
answered on 18 Oct 2010, 06:30 AM
Are you trying to delete the files from the target folder or the temporary folder?  

Fred
0
Jesse Lawler
Top achievements
Rank 1
answered on 18 Oct 2010, 08:14 PM
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!
0
Fred Mare
Top achievements
Rank 1
answered on 18 Oct 2010, 08:29 PM
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
0
Genady Sergeev
Telerik team
answered on 21 Oct 2010, 01:49 PM
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
0
Fred Mare
Top achievements
Rank 1
answered on 22 Oct 2010, 09:22 AM
Dear Genady

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

Fred

 
0
Jesse Lawler
Top achievements
Rank 1
answered on 23 Oct 2010, 01:21 AM
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
0
Genady Sergeev
Telerik team
answered on 27 Oct 2010, 10:34 AM
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
0
Kartar
Top achievements
Rank 1
answered on 14 May 2012, 12:27 PM
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.

0
Princy
Top achievements
Rank 2
answered on 14 May 2012, 01:57 PM
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.
0
Kartar
Top achievements
Rank 1
answered on 14 May 2012, 02:21 PM
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!!!!!!
Tags
Upload (Obsolete)
Asked by
Fred Mare
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Fred Mare
Top achievements
Rank 1
Jesse Lawler
Top achievements
Rank 1
Kartar
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or