Removing files from Items array doesn't work properly

6 posts, 0 answers
  1. Andy Obermoller
    Andy Obermoller avatar
    2 posts
    Member since:
    Oct 2007

    Posted 25 Aug 2009 Link to this post

    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.
  2. Andy Obermoller
    Andy Obermoller avatar
    2 posts
    Member since:
    Oct 2007

    Posted 25 Aug 2009 Link to this post

    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.
  3. Kiril Stanoev
    Kiril Stanoev avatar
    1512 posts

    Posted 26 Aug 2009 Link to this post

    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.
  4. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 08 Dec 2010 Link to this post

    Thank you Andy for mentioning ShowValidFiles and telling to clear the Items list.
    This helped me solve my problem while using the control programatically.
  5. Abrian
    Abrian avatar
    1 posts
    Member since:
    Jul 2012

    Posted 30 Aug 2012 Link to this post

    What was the answer to this question?
  6. Tina Stancheva
    Tina Stancheva avatar
    3299 posts

    Posted 04 Sep 2012 Link to this post

    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.

    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top