When I try to delete an write protected file, I get an UnauthorizedAccessException. Permissions are fine, I can delete the file, if I remove the write-protection-box in Explorer->File properties.
How can I delete the file anyway?
When I try to delete an write protected file, I get an UnauthorizedAccessException. Permissions are fine, I can delete the file, if I remove the write-protection-box in Explorer->File properties.
How can I delete the file anyway?
As long as you have enough rights on that file (permissions), you can remove all attributes on that file and then delete it:
var fileName = "c:\\temp\\test.txt"
// Handle write protected files: Remove all special attributes.
File.SetAttributes(fileName, FileAttributes.Normal);
File.Delete(fileName);