C#文件夹权限操作工具类
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#文件夹权限操作工具类的更多相关文章
- 转发:entos7修改文件夹权限和用户名用户组
Linux系统下经常遇到文件或者文件夹的权限问题,或者是因为文件夹所属的用户问题而没有访问的权限.根据我自己遇到的情况,对这类问题做一个小结.在命令行使用命令“ll”或者“ls -a”,可以查看文件或 ...
- centos6.5下修改文件夹权限和用户名用户组
0.说明 Linux系统下经常遇到文件或者文件夹的权限问题,或者是因为文件夹所属的用户问题而没有访问的权限.根据我自己遇到的情况,对这类问题做一个小结. 在命令行使用命令"ll"或 ...
- Centos7修改文件夹权限和用户名用户组
Linux系统下经常遇到文件或者文件夹的权限问题,或者是因为文件夹所属的用户问题而没有访问的权限.根据我自己遇到的情况,对这类问题做一个小结.在命令行使用命令“ll”或者“ls -a”,可以查看文件或 ...
- asp.net自己创建的app_code文件夹中的类不能访问的解决办法
在Web应用程序中不能通过右键项目-〉”添加“-〉”添加ASP.NET文件夹“方式添加 .因为Web应用程序中App_Code就不存在 .不过可以通过手动的方式创建,添加一个文件夹命名为App_Cod ...
- php apache用户写文件夹权限设置
php一般是以apache用户身份去执行的,把apache加入到存储你文件的父文件夹属组里去,然后改该父文件夹权限为775,这样属组成员就有写的权限,而apache属于这个组就可以改写该目录下所有文件 ...
- ubuntu chmod 无法更改 文件夹权限 系统提示“不允许的操作 2、linux 如何修改只读文件 3、ubuntu安装
1.ubuntu chmod 无法更改 文件夹权限 系统提示“不允许的操作 答案:需要超级用户权限 sudo 2.linux 如何修改只读文件 答案:可以使用chmod命令,为改文件提供其他的权限.u ...
- Linux chmod命令修改文件与文件夹权限的命令附实例
Linux chmod命令修改文件与文件夹权限的命令附实例 作者:佚名 字体:[增加 减小] 来源:互联网 时间:05-01 20:46:07我要评论 在linux中要修改一个文件夹或文件的权限我们需 ...
- Linux命令(14)文件和文件夹权限管理:chmod
linux文件和文件夹权限简介: chmod命令用于改变linux系统文件或目录的访问权限.用它控制文件或目录的访问权限. Linux系统中的每个文件和目录都有访问许可权限,用它来确定谁可以通过何种方 ...
- Java中创建操作文件和文件夹的工具类
Java中创建操作文件和文件夹的工具类 FileUtils.java import java.io.BufferedInputStream; import java.io.BufferedOutput ...
随机推荐
- 清空npm缓存
nodejs 清空 npm 缓存 npm cache clean -f
- 怎样编写YARN应用程序
(注意:本文的分析基于Hadoop trunk上的"Revision 1452188"版本号,详细可參考:http://svn.apache.org/repos/asf/hadoo ...
- ASP入门(十三)-Server对象
Server 对象用于处理服务器上的一些特殊任务,例如,创建组件实例.获取文件路径.执行ASP脚本文件等. Server 对象是体现 ASP 强大功能的一个对象,之前介绍的对象都是针对获取.请求以及简 ...
- 程序员的福音,AI可以自动修复bug了!
人工智能完全学会自己编程,可能说起来还有一种科幻感,但 AI 帮程序员找 bug 这件事,已经达到了不错的水平. 北京大学.微软亚洲研究院和中国电子科技大学就一起尝试着让 AI 找 bug.微软亚洲研 ...
- CSS3实现的苹果网站搜索框效果
在线演示 本地下载 用CSS3相关属性生成的动态搜索框效果.
- 从 bootup.js 学习加载脚本等资源
本文内容 如何使用 示例 参考资料 本文的目的在于,通过 bootup.js 的源代码,认识如何从客户端加载服务器的文件,特别是 JavaScript 文件,注入到页面,并存储在本地缓存,以扩展对 J ...
- DFS csu1719 Boggle
传送门:id=1719">点击打开链接 题意:真正的题意是,告诉你一些字符串.然后告诉你非常多个字符格子,问这些字符串是否能在字符格子中连起来,在格子中对角线也觉得是连在一起的.假设格 ...
- Angularjs 中的 controller
接触过程序开发的小伙伴们对 MVC 的开发方式想必一点也不陌生,是的, angularjs 所採用的方式便是 MVVM 的开发方式,这里的 controller 即控制器 了解 controller ...
- 牛客网-《剑指offer》-变态跳台阶
C++ class Solution { public: int jumpFloorII(int n) { <<--n; } }; 推导: 关于本题,前提是n个台阶会有一次n阶的跳法.分析 ...
- 第八周(1) Word信函与邮件
第八周(1) Word信函与邮件 教学时间 2013-4-15 教学课时 2 教案序号 13 教学目标 1.学会使用word制作信封和标签2.理解邮件合并的概念和功能3.学会利用邮件合并批量制作文档 ...