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

Error Removing Images From RadRotator

1 Answer 108 Views
Rotator
This is a migrated thread and some comments may be shown as answers.
Chance Robertson
Top achievements
Rank 1
Chance Robertson asked on 18 May 2010, 02:34 PM
Hello-

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) 
 
                        items.Add(radItem); 
                    ((RadImageItem) radItem).Image = null
                } 
 
                photoRadRotator.Items.Clear(); 
                currentItem.Dispose(); 
                this.RemovePhotos(fileNameString); 
            } 

Here is the code for the last line the RemovePhotos method:
            if (!Directory.Exists(m_unusedFolder)) 
            { 
                Directory.CreateDirectory(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?

Thanks,
Chance

1 Answer, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 21 May 2010, 01:57 PM
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.
 
Greetings,
Victor
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.
Tags
Rotator
Asked by
Chance Robertson
Top achievements
Rank 1
Answers by
Victor
Telerik team
Share this question
or