C#创建文件夹并设置权限
2008-07-25 13:56
330 查看
string sPath = Server.MapPath(文件夹名称字符串);
Directory.CreateDirectory(sPath);
addpathPower(sPath, "ASPNET", "FullControl");
public void addpathPower(string pathname, string username, string power)
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.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow));
break;
case "ReadOnly":
dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.Read, AccessControlType.Allow));
break;
case "Write":
dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.Write, AccessControlType.Allow));
break;
case "Modify":
dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.Modify, AccessControlType.Allow));
break;
}
dirinfo.SetAccessControl(dirsecurity);
}
Directory.CreateDirectory(sPath);
addpathPower(sPath, "ASPNET", "FullControl");
public void addpathPower(string pathname, string username, string power)
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.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow));
break;
case "ReadOnly":
dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.Read, AccessControlType.Allow));
break;
case "Write":
dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.Write, AccessControlType.Allow));
break;
case "Modify":
dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.Modify, AccessControlType.Allow));
break;
}
dirinfo.SetAccessControl(dirsecurity);
}
相关文章推荐
- C#创建文件夹并设置权限
- C# 创建文件夹 并 设置权限
- C#创建文件夹并设置权限
- C#设置文件夹用户权限
- 创建本地用户和设置NTFS文件夹权限
- c# 设置文件夹权限
- 转载:C# 设置文件夹权限(代码简单)
- [原]C#设置文件夹用户权限
- c#中为文件夹设置权限
- c#中为文件夹设置权限
- 公司员工没有管理员权限怎么办 C#文件夹、文件添加权限 C#读取windows系统日志 C#设置环境变量
- C# 设置文件夹的访问权限
- 用 C# 给文件夹设置 NTFS 权限(ACL)
- C#设置文件夹用户权限
- c#中为文件夹设置权限
- 在Win XP及Win 2003下使用程序方式(C#)设置共享文件夹的文件夹权限的问题及解决方案。
- 创建并设置文件夹的NTFS权限
- Mac OSX 设置文件夹下特定用户组创建文件默认权限
- c#中为文件夹设置权限
- C#设置文件夹权限