using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks; namespace CvNetVideo.Play
{
/// <summary>
/// 目录权限辅助类
/// </summary>
public class DictionaryHelper
{
/// <summary>
/// 需要足够的权限才能执行此操作:Get filepath rights
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static List<FileSystemRights> GetRights(string path)
{
List<FileSystemRights> ret = new List<FileSystemRights>(); DirectorySecurity dirSec = Directory.GetAccessControl(path, AccessControlSections.All);
AuthorizationRuleCollection rules = dirSec.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));
foreach (FileSystemAccessRule rule in rules)
{
ret.Add(rule.FileSystemRights);
}
return ret;
} //public static void AccessExample() {
// try
// {
// string DirectoryName = "TestDirectory"; // Console.WriteLine("Adding access control entry for " + DirectoryName); // // Add the access control entry to the directory.
// AddDirectorySecurity(DirectoryName, @"MYDOMAIN\MyAccount", FileSystemRights.ReadData, AccessControlType.Allow); // Console.WriteLine("Removing access control entry from " + DirectoryName); // // Remove the access control entry from the directory.
// RemoveDirectorySecurity(DirectoryName, @"MYDOMAIN\MyAccount", FileSystemRights.ReadData, AccessControlType.Allow); // Console.WriteLine("Done.");
// }
// catch (Exception e)
// {
// Console.WriteLine(e);
// } // Console.ReadLine();
//} // Adds an ACL entry on the specified directory for the specified account.
public static void AddDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
{
// Create a new DirectoryInfo object.
DirectoryInfo dInfo = new DirectoryInfo(FileName); // Get a DirectorySecurity object that represents the
// current security settings.
DirectorySecurity dSecurity = dInfo.GetAccessControl(); // Add the FileSystemAccessRule to the security settings.
dSecurity.AddAccessRule(new FileSystemAccessRule(Account,
Rights,
ControlType)); // Set the new access settings.
dInfo.SetAccessControl(dSecurity); } // Removes an ACL entry on the specified directory for the specified account.
public static void RemoveDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
{
// Create a new DirectoryInfo object.
DirectoryInfo dInfo = new DirectoryInfo(FileName); // Get a DirectorySecurity object that represents the
// current security settings.
DirectorySecurity dSecurity = dInfo.GetAccessControl(); // Add the FileSystemAccessRule to the security settings.
dSecurity.RemoveAccessRule(new FileSystemAccessRule(Account,
Rights,
ControlType)); // Set the new access settings.
dInfo.SetAccessControl(dSecurity); }
}
}

C#文件夹权限操作工具类的更多相关文章

  1. 转发:entos7修改文件夹权限和用户名用户组

    Linux系统下经常遇到文件或者文件夹的权限问题,或者是因为文件夹所属的用户问题而没有访问的权限.根据我自己遇到的情况,对这类问题做一个小结.在命令行使用命令“ll”或者“ls -a”,可以查看文件或 ...

  2. centos6.5下修改文件夹权限和用户名用户组

    0.说明 Linux系统下经常遇到文件或者文件夹的权限问题,或者是因为文件夹所属的用户问题而没有访问的权限.根据我自己遇到的情况,对这类问题做一个小结. 在命令行使用命令"ll"或 ...

  3. Centos7修改文件夹权限和用户名用户组

    Linux系统下经常遇到文件或者文件夹的权限问题,或者是因为文件夹所属的用户问题而没有访问的权限.根据我自己遇到的情况,对这类问题做一个小结.在命令行使用命令“ll”或者“ls -a”,可以查看文件或 ...

  4. asp.net自己创建的app_code文件夹中的类不能访问的解决办法

    在Web应用程序中不能通过右键项目-〉”添加“-〉”添加ASP.NET文件夹“方式添加 .因为Web应用程序中App_Code就不存在 .不过可以通过手动的方式创建,添加一个文件夹命名为App_Cod ...

  5. php apache用户写文件夹权限设置

    php一般是以apache用户身份去执行的,把apache加入到存储你文件的父文件夹属组里去,然后改该父文件夹权限为775,这样属组成员就有写的权限,而apache属于这个组就可以改写该目录下所有文件 ...

  6. ubuntu chmod 无法更改 文件夹权限 系统提示“不允许的操作 2、linux 如何修改只读文件 3、ubuntu安装

    1.ubuntu chmod 无法更改 文件夹权限 系统提示“不允许的操作 答案:需要超级用户权限 sudo 2.linux 如何修改只读文件 答案:可以使用chmod命令,为改文件提供其他的权限.u ...

  7. Linux chmod命令修改文件与文件夹权限的命令附实例

    Linux chmod命令修改文件与文件夹权限的命令附实例 作者:佚名 字体:[增加 减小] 来源:互联网 时间:05-01 20:46:07我要评论 在linux中要修改一个文件夹或文件的权限我们需 ...

  8. Linux命令(14)文件和文件夹权限管理:chmod

    linux文件和文件夹权限简介: chmod命令用于改变linux系统文件或目录的访问权限.用它控制文件或目录的访问权限. Linux系统中的每个文件和目录都有访问许可权限,用它来确定谁可以通过何种方 ...

  9. Java中创建操作文件和文件夹的工具类

    Java中创建操作文件和文件夹的工具类 FileUtils.java import java.io.BufferedInputStream; import java.io.BufferedOutput ...

随机推荐

  1. ASP入门(三)-VBScript变量、运算符

    ASP内置了两种语法引擎,分别是VBScript和JScript. VBScript是VB的一个子集.JScript和JavaScript有些类似. 如果你熟悉VB,建议用VBScript,否则推荐使 ...

  2. 极域电子教室卸载或安装软件后windows7无法启用触摸板、键盘

    我今天在win7上装了个极域电子教室,卸载后重启触摸板,键盘都不能用了?连口令都是用屏幕键盘来输入的.进去后看设备管理器,键盘和触摸板,前面都有黄色的告警,而且就是出现了鼠标代码为10的情况?不过吧鼠 ...

  3. GitHub没有实时通知怎么办?当然是自己上手写一个啊!

    相信各位程序员对github已经不陌生了.不知道各位有没有注意到GitHub没有推送通知这个功能.当有人在我的存储库中创建了一个提取请求/问题时,我可以收到电子邮件通知,但当有人stars/forks ...

  4. windows安装mycat(转)

    http://blog.csdn.net/sc9018181134/article/details/53063798 1.先到github上下载mycat 2.下载完成后,解压.应该是这样一个样子 3 ...

  5. Linux开机自动启动某一程序

    Linux开机启动程序详解我们假设大家已经熟悉其它操作系统的引导过程,了解硬件的自检引导步骤,就只从Linux操作系统的引导加载程序(对个人电脑而言通常是LILO)开始,介绍Linux开机引导的步骤. ...

  6. hibernate5(12)注解映射[4]一对一外键关联

    在实际博客站点中,文章内容的数据量非常多,它会影响我们检索文章其他数据的时间,如查询公布时间.标题.类别的等. 这个时候,我们能够尝试将文章内容存在还有一张表中,然后建立起文章--文章内容的一对一映射 ...

  7. 算法笔记_199:第二届蓝桥杯软件类决赛真题(C语言本科)

    前言:以下代码部分仅供参考,C语言解答部分全部来自网友,Java语言部分部分参考自网友,对于答案的正确性不能完全保证. 试题1 数论中有著名的四方定理:所有自然数至多只要用四个数的平方和就可以表示. ...

  8. Python标准库:内置函数bytes([source[, encoding[, errors]]])

    返回一个新的数组对象,这个数组对象不能对数组元素进行改动.每一个元素值范围: 0 <= x < 256.bytes函数与bytearray函数主要差别是bytes函数产生的对象的元素不能改 ...

  9. Java并发容器之阻塞队列BlockingQueue

    BlockingQueue提供了线程安全的队列访问方式:当阻塞队列进行插入数据时,如果队列已满,线程将会阻塞等待直到队列非满:从阻塞队列取数据时,如果队列已空,线程将会阻塞等待直到队列非空. Bloc ...

  10. Configuring the launch of the remote virtual machine to debug

    Options need to be added to the standard launch of a virtual machine (VM) to enable the debugging ar ...