Reputation: 9393
I used this code to deny permissions to a file. It worked perfectlly.
string fileName = @"c:\untitled.jpg";
FileSecurity fSecurity = File.GetAccessControl(fileName);
fSecurity.AddAccessRule(new FileSystemAccessRule("Everyone",
FileSystemRights.FullControl, AccessControlType.Deny));
File.SetAccessControl(fileName, fSecurity);
and the below piece of code to reset the access controls
fSecurity.ResetAccessRule(new FileSystemAccessRule("Everyone",
FileSystemRights.FullControl, AccessControlType.Allow));
Now when I set permissions to a file. I don't want some other people to reset the permissions to the file but when I opened a new project and copied the code to reset access rules to the file, it has reset the permissions to the file. I don't want that to be happen.
I only want my C# code to reset the permissions of the file because the people who knows the C# programming can easily reset the permissions to a file that has been denied with my C# code.
Can I block some one else from resetting the permissions a file through my c# code? The file permissions should be reset only through my C# code.
Upvotes: 0
Views: 147
Reputation: 1655
Anyone else can write the same code you've written to update the permissions so you can't do it through code (unless your program runs permanently and you lock the file)
You're better off managing this via Windows NTFS permissions so the users of the other apps don't have permission to change permissions (and therefore neither does the ap they're running)
Upvotes: 2