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

Removing files from Items array doesn't work properly

5 Answers 116 Views
Upload
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Andy Obermoller
Top achievements
Rank 1
Andy Obermoller asked on 25 Aug 2009, 04:08 PM
First.. a little information about the app I'm building..

So I'm implementing an uploader in my application and I'm looking for multiple different views for the uploader contents.

A view during selection that shows the file information, a visual icon representing the file and some input fields to provide additional data.
A second view will be a 'summary' view that displays a smaller icon and the file info for each file.
A third view that shows the progress bars for each individual file as they upload.

My plan is to implement the first 2 views using an ObservableCollection that I populate by capturing the FilesSelected event. I would then bind these views to this collection and do my work there. The third view with the progress bars would be the actual display from the RadUpload control with its Template set to only display the information I'm interested in.

I have this working... to a point. I can create my collection, bind to it for display and show the RadUpload control when I need to.

What I can't get functioning.. is removing files from the list to be uploaded. Presently what I'm doing is removing the appropriate element from both my collection and the RadUpload.Items collection.... The display updates as expected and no longer shows the files that were removed.

However when I open the Browse Dialog again.. as soon as I select new files, the RadUpload.Items collection now includes the items that I had removed previously.

So if this isn't the appropriate way to remove a file from the list.. please.. tell me what is.

5 Answers, 1 is accepted

Sort by
0
Andy Obermoller
Top achievements
Rank 1
answered on 25 Aug 2009, 10:23 PM
After trying many different things I finally grabbed your source code and realized the issue.

In the private method RadUpload.ShowValidFiles() you guys are rebuilding the RadUpload.Items array based on RadUpload.CurrentSession.ValidFiles... This method is called in RadUpload.OnFileSelected which leads to the array being repopulated EVERY time a new file selection occurs.

So to make my code work I've begun searching the ValidFiles collection to remove my file from there as well.

I'd recommend changing how this functions in a future build or at the very least making sure that when you recommend deleting files via RadUpload.Items.Clear that you mention the ValidFiles array.
0
Kiril Stanoev
Telerik team
answered on 26 Aug 2009, 11:24 AM
Hello Andy,

I have posted an answer to your support ticket.

Best wishes,
Kiril Stanoev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Jonx
Top achievements
Rank 2
answered on 09 Dec 2010, 04:16 AM
Thank you Andy for mentioning ShowValidFiles and telling to clear the Items list.
This helped me solve my problem while using the control programatically.
0
Abrian
Top achievements
Rank 2
answered on 30 Aug 2012, 02:30 PM
What was the answer to this question?
0
Tina Stancheva
Telerik team
answered on 04 Sep 2012, 02:04 PM
Hi Abrian,

With the latest version of the RadUpload control, next to each item there is a button that allows you to remove the corresponding  RadUploadItem. This button uses a DeleteCommand which you can utilize in case you need to create a custom logic for removing an item. For example the following code snippet demonstrates how to remove the last file in the RadUpload control:
private void RadButton_Click(object sender, RoutedEventArgs e)
{
    int itemsCount = xRadUpload.Items.Count;
    if (itemsCount > 2)
    {
        (xRadUpload.Items[itemsCount - 1] as RadUploadItem).DeleteCommand.Execute(null);
    }
}

Give this a try and let me know if it helps.

Regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Upload
Asked by
Andy Obermoller
Top achievements
Rank 1
Answers by
Andy Obermoller
Top achievements
Rank 1
Kiril Stanoev
Telerik team
Jonx
Top achievements
Rank 2
Abrian
Top achievements
Rank 2
Tina Stancheva
Telerik team
Share this question
or