[已关闭问题] 设置文件权限的问题
提问时间: 2008-05-15 11:23
提问时间2008/5/15 11:23:35 问题为何被关闭 浏览:92 次

根据网上查询,写了一个如下的方法:

public bool AddpathPower(string pathname, string username, string power)
        {

            try
            {
                DirectoryInfo dirinfo = new DirectoryInfo(pathname);

                if ((dirinfo.Attributes & FileAttributes.ReadOnly) != 0)
                {
                    dirinfo.Attributes = FileAttributes.Normal;
                }

                //取得访问控制列表
                DirectorySecurity dirsecurity = dirinfo.GetAccessControl();

                switch (power)
                {
                    case "FullControl":
                        dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.FullControl, InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow));
                        break;
                    case "ReadOnly":
                        dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.Read, AccessControlType.Allow));
                        break;
    &am

提问者:李.net - 小虾三级
   您需要登录以后才能回答!
我的问题    我要提问


快到期问题

> 问题排行榜

有不合适内容,建议去除