Click here to Skip to main content
14,930,487 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to delete temp files and folders, I got success in deleting all sub-folders of temp folder but one file creating permissions related problem in deletion. Is there any way to delete that file or skip that file??

Please help, if anyone having idea.

Thanks in advance.

Use the FileOptions.DeleteOnClose option when creating the file you can't delete now. If any other processes open this file, see this: [^].
AdityaBohra 27-Jan-14 12:41pm
Thanks Bill
This must be a file that must be locked since it is getting used presently.
You should'nt and won't be able to delete it.
Do NOT repost the same question again and again. Continue the discussion in your original thread.
Dear Aditya,

First thing do check the permission on the file or directory which you are trying to delete. Provide a if condition check and thn delete the files.

Here is the code snippet

AuthorizationRuleCollection acl = fileSecurity.GetAccessRules(true, true,typeof(System.Security.Principal.SecurityIdentifier));
bool denyEdit = false;
for (int x = 0; x < acl.Count; x++)
FileSystemAccessRule currentRule = (FileSystemAccessRule)acl[x];
AccessControlType accessType = currentRule.AccessControlType;

if (accessType == AccessControlType.Deny && (currentRule.FileSystemRights & FileSystemRights.ListDirectory) == FileSystemRights.ListDirectory)

denyEdit = true;


Praveen Nelge

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