zoukankan      html  css  js  c++  java
  • C#创建文件夹并设置权限

    原文地址:https://www.cnblogs.com/top5/archive/2010/04/12/1710141.html

    /*  
    需要添加以下命名空间:  
    using System.IO;  
    using System.Security.AccessControl;  
    */  
      
    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);   
    }

  • 相关阅读:
    python -django 之第三方支付
    python 的排名,已经python的简单介绍
    第三方登录
    linux 基础命令
    JWT 加密
    Docker 简介
    中文分词库:结巴分词
    Django websocket 长连接使用
    jQuery截取字符串的几种方式
    Python 操作redis
  • 原文地址:https://www.cnblogs.com/boonya/p/9013559.html
Copyright © 2011-2022 走看看