Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
after copying the file to another destination i want to delete the file from origin.
I am unable to do so as file is used by another process

File.Copy(FullPath, strErrorFile, true);
File.Delete(FullPath);
Posted

find out which process is using the file

Quote:
How to find out which handle or DLL is using a file
Open Process Explorer, running as administrator.
Enter the keyboard shortcut Ctrl+F. Altenatively, click the “Find” menu and select “Find a Handle or DLL”.
A search dialog box will open.
Type in the name of the locked file or other file of interest.


(there are other ways of doing that - Process Explorer from SysInternals *may* help)

if it's your own process, you may need a delay between the copy and delete or some other method of flushing/forcing your process to let go of the file
 
Share this answer
 
You will need to investigate what's going on. To do so, start with reading my past answer on this topic: how to compress the error 'it is already used by another process' in vb.net[^].

—SA
 
Share this answer
 

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