Click here to Skip to main content
15,884,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,
I have written a winform application in visual studio 2010.In one of the forms the user can browse the local system and select an image, so the application will copy that image(with File.Copy() method) to its folder.
the problem is when the user wants to delete that image(File.Delete() method),I receive an error like this :

cannot delete this file because it is used by another process.


I do not know what this error says because i do not use the image files in other processes.
Posted

Make sure that the file is not open in another program like paint etc.
 
Share this answer
 
Comments
M_Mogharrabi 5-May-12 1:19am    
I am sure that my images are not open in another processes.
Since, the error message says that the file is used by another process, the file handle may be in use by some process which is not clear. To check for that I think the Process Explorer By Mark Russinovich
which can be downloaded from here
Process Explorer v15.13[^]
can be used to ascertain whether any process is holding this file handle.
 
Share this answer
 
how does the user delete the file?
to delete the file,user will select the file.
and then select delete.
but when user selects it, File.Copy() is executed and when u try to delete,File.Delete() is blocked because File.Copy() is still accessing it.

File.Copy() is "another process " which is accessing it.
so to achieve your goal u need to call File.Delete() after a small interval[depends on selected file's size].
 
Share this answer
 
v2
Comments
M_Mogharrabi 5-May-12 5:13am    
Hi Silent Guardian and thanks for your reply but i do not think so.because the steps of this operation is something like this :
1. the user browse the system and select an image.
2. application copies that image to its folder with File.Copy() and add its name to a list.
3. the user select the name of image from list and then press delete button.
4. application should now delete an image with this name from its directory(the error will occur here)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900