Click here to Skip to main content
15,913,453 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am copying Windows directory from "C:" drive to "E:" drive. When we try to delete this directory from C# application then application throws "Access denied file" exception.

If we try to delete it manually, then it gets deleted successfully.
Posted
Updated 19-Aug-14 3:45am
v2
Comments
Nathan Minier 19-Aug-14 9:27am    
You can get the access denied for a few reasons. It may not have closed the file or might still have a reference to the handle so cannot delete it. It also might be that your Local System doesn't have privileges in that folder.
Sergey Alexandrovich Kryukov 19-Aug-14 12:15pm    
Why, why would you do this copy?!
—SA

Depends on how your app is running to an extent: if it is started directly by your user then it runs with your user permissions. If it is started in some other way - as a service, or from a different application for example, then it will get different permissions as it doesn't run as the user.

You may be able to get round this by elevating your app, or by changing the access permissions on the folder when it is created.
 
Share this answer
 
Comments
Jadhav Gangadhar 20-Aug-14 1:44am    
I have copied this directory same user and when I delete it normally then it deleted.
OriginalGriff 20-Aug-14 4:38am    
How exactly are you copying it, and how are you deleting it?
If you are using code, then show us, and explain what works, what doesn't, and what happens.
Might be that your application in running in the folder you are trying to delete. That won't work either.

Good luck!
 
Share this answer
 
I cannot imagine that the copy of the content of this directory can ever be useful. It' won't make Windows installed on the other drive. Windows OS is not all put to this directory. Moreover, some files in this directory may not work in another location even if the same version of Windows is actually loaded and started.

—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