Reputation: 23
I am opening a file from a location (say, X) in a PictureBox.
After that, if the user clicks on a button say "btn1" then I copy the file from Location X to Location Y using File.Copy()
.
After that I set the Picturebox1.Image=null;
...and use File.Delete(X);
At this point Visual studio shows me the exception that The file cannot be deleted as it is being used by another process.
Any ideas as to why would that be?
Upvotes: 1
Views: 1677
Reputation: 5912
You can use File.Move() as workaround http://msdn.microsoft.com/en-us/library/system.io.file.move.aspx
Upvotes: 1
Reputation: 191058
Make sure you are disposing the original Image
.
Otherwise, another program has a handle on it.
Upvotes: 0