How to provide security to files and folders throu

2019-08-27 23:38发布

问题:

I have created a folder lock in C#.NET which is working good on NTFS file system But its not working on FAT file system. please tell which dll/class/namespace should i use to get Lock files and folder on FAT file system through C#.NET

sample code which is working with NTFS (below code is to unlock file/folder)

FileInfo info = new FileInfo(folderpath);
FileSecurity accessControl = info.GetAccessControl(AccessControlSections.All);
accessControl.RemoveAccessRule(
    new FileSystemAccessRule(
        Environment.UserName.ToString(), 
        FileSystemRights.FullControl, 
        AccessControlType.Deny));

accessControl.SetSecurityDescriptorSddlForm(
    "D:(A;;GAGRGWGXRCSDWDWORPWPCCDCLCSWLODTCR;;;WD)", 
    AccessControlSections.All);
info.SetAccessControl(accessControl);

回答1:

You cannot. The FAT file system does not support many advanced features, such as access control lists. (Basically the only feature resembling access control in FAT is the "read only" file attribute bit, which applies to every user)



回答2:

The FAT file system does not support security so you are not able to set ACLs in the way you illustrate in your question.

More details can be found at Wikipedia