C# Creating directory and setting the permissions

前端 未结 1 1742
无人及你
无人及你 2021-01-18 18:50

I am trying to use the code below to allow all users be able to modify a folder:

class Program
{
    private const string FileName = \"test.txt\";
    privat         


        
相关标签:
1条回答
  • 2021-01-18 19:49

    You can use the Directory.SetAccessControl().

    Example:

    DirectoryInfo directory = new DirectoryInfo(@"C:\my\directory");
    DirectorySecurity security = directory.GetAccessControl();
    
    security.AddAccessRule(new FileSystemAccessRule(@"MYDOMAIN\JohnDoe", 
                            FileSystemRights.Modify, 
                            AccessControlType.Deny));
    
    directory.SetAccessControl(security);   
    

    More details in the msdn.

    0 讨论(0)
提交回复
热议问题