W
wo20051223
Deleting some files with C# fails with "Access to the path 'X' is
denied".
I have files copied from a CD that I burned (and not locked by a
process) and a text file that I created in Windows Explorer. I can
delete all of them through Windows Explorer. I can programmatically
delete the text file but not the others.
Permissions:
- All files have the same ACL.
- I checked WindowsIdentity.GetCurrent().Name in the debugger right
before the delete: same user as the Windows Explorer delete.
Delete functions:
I tried:
- Directory.Delete ( path, true /*recursive*/ );
- DirectoryInfo di = new DirectoryInfo(@"c:\MyDir"); di.Delete();
- File.Delete ( path );
- [DllImport("Kernel32.dll")]
public static extern bool RemoveDirectory(string lpPathName);
- [DllImport("Kernel32.dll")]
public static extern bool DeleteFile(string lpPathName);
Environment:
- Win XP Pro SP 2
- VS 2003
- .NET Framework v1.1
denied".
I have files copied from a CD that I burned (and not locked by a
process) and a text file that I created in Windows Explorer. I can
delete all of them through Windows Explorer. I can programmatically
delete the text file but not the others.
Permissions:
- All files have the same ACL.
- I checked WindowsIdentity.GetCurrent().Name in the debugger right
before the delete: same user as the Windows Explorer delete.
Delete functions:
I tried:
- Directory.Delete ( path, true /*recursive*/ );
- DirectoryInfo di = new DirectoryInfo(@"c:\MyDir"); di.Delete();
- File.Delete ( path );
- [DllImport("Kernel32.dll")]
public static extern bool RemoveDirectory(string lpPathName);
- [DllImport("Kernel32.dll")]
public static extern bool DeleteFile(string lpPathName);
Environment:
- Win XP Pro SP 2
- VS 2003
- .NET Framework v1.1