Take a look at the following article,
Delete Undeletable Folders under Vista or Windows 7[
^]. It explains how to gain access to the files / folder which are otherwize not accessable as in your case.
From the article
=========================
The main idea behind the program is to fix the access rights for every file and folder.
private static void FixAccess(FileSystemSecurity sec)
{
string currentUser = WindowsIdentity.GetCurrent().Name;
sec.AddAccessRule(new FileSystemAccessRule
(currentUser, FileSystemRights.FullControl, AccessControlType.Allow));
}
I also clear all the existing rules in the hope that it will avoid conflicts.
foreach (FileSystemAccessRule fsar in sec.GetAccessRules
(true, true, typeof(System.Security.Principal.NTAccount)).OfType<filesystemaccessrule />().ToArray())
{
sec.RemoveAccessRuleAll(fsar);
}
Unfortunately, most of this was failing at the beginning and I could not find out why. I thought the solution was to fix the ownership of the file.
private static void FixOwner(FileSystemSecurity sec)
{
var sid = sec.GetOwner(typeof(SecurityIdentifier));
string currentUser = WindowsIdentity.GetCurrent().Name;
var ntAccount = new NTAccount(currentUser);
sec.SetOwner(ntAccount);
}