Error Removing Images From RadRotator

2 posts, 0 answers
  1. Chance Robertson
    Chance Robertson avatar
    1 posts
    Member since:
    Jan 2010

    Posted 18 May 2010 Link to this post


    I have created a UserControl with the RadRotator on it and 4 buttons.  1 for Previous, 1 for View, 1 for Remove, and 1 for Next.  All the buttons work except the Remove button.  Here is my code to add images to the RadRotator:

    foreach (FileInfo  photoFileInfo in m_photos) 
                    Bitmap photoBitmap = new Bitmap(Image.FromFile(photoFileInfo.FullName), 313, 253); 
                    RadImageItem radImageItem = new RadImageItem 
                                                        Image = photoBitmap, 
                                                        Tag = photoFileInfo.Name 
                    this.InvokeIfNeeded(() => photoRadRotator.Items.Add(radImageItem)); 

    The Remove button calls the RemovePhoto Method.  Here is the event handler for the delete button:
    if (photoRadRotator.CurrentItem != null
                    RadItem currentItem = photoRadRotator.CurrentItem; 
                    string fileNameString = currentItem.Tag.ToString(); 
                    foreach (RadItem radItem in photoRadRotator.Items) 
                        List<RadItem> items = new List<RadItem>(); 
                        if (radItem != currentItem) 
                        ((RadImageItem) radItem).Image = null

    Here is the code for the last line the RemovePhotos method:
                if (!Directory.Exists(m_unusedFolder)) 
                File.Move(Path.Combine(m_associatedFolder, fileToRemove), 
                          Path.Combine(m_unusedFolder, fileToRemove)); 

    I an error on the File.Move line that says the file is in use by another process.  I have determined that the RadRotator i still holding on to the file through the Image property of the RadImageItem.  I am trying to allow a user to look through a directory of photos using the RadRotator.  If they find a photo they want to remove, they click the delete button and the photo is removed from the RadRotator and moved to another directory.  

    How can I programmatically remove an item from the RadRotator and then move it to another directory without the RadRotator still having a lock on the file?

  2. Victor
    Victor avatar
    1358 posts

    Posted 21 May 2010 Link to this post

    Hello Chance Robertson,

    Thank you for writing.

    In this case RadRotator is not the cause of the file being locked. If you refer to the MSDN page for the Image.FromFile() method you will notice that the "Remarks" section says the following:

    "The file remains locked until the Image is disposed."

    Write again if you need further assistance.
    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.
Back to Top