C#设置文件夹权限

原文链接: http://www.cnblogs.com/zhao159357222/archive/2013/04/11/3014479.html

对文件夹设置为Everyone的权限,首先需要先添加引用

using System.Security.AccessControl;

采用下面的方法对文件夹设置Everyone权限

        /// <summary>
        /// 设置文件夹权限,处理为Everyone所有权限
        /// </summary>
        /// <param name="foldPath">文件夹路径</param>
        public static void SetFileRole(string foldPath)
        {
            DirectorySecurity fsec = new DirectorySecurity();
            fsec.AddAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.FullControl,
                InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
            System.IO.Directory.SetAccessControl(foldPath, fsec);
        }    

转载于:https://www.cnblogs.com/zhao159357222/archive/2013/04/11/3014479.html

猜你喜欢

转载自blog.csdn.net/weixin_30193897/article/details/95015323