c#操作文件夹得读写权限

对文件夹设置为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);
        }    

另外也可以参考下http://www.cnblogs.com/leosky2008/archive/2007/08/08/847405.html

原文地址:https://www.cnblogs.com/oracleblogs/p/3359699.html