• C#设置文件(夹)权限


    C#设置账户对文件的访问权限为完全访问

            /// <summary>
            /// 将账户对文件的访问权限设置为完全访问
            /// </summary>
            /// <param name="filePath">文件路径</param>
            /// <param name="userName">账户名</param>
            private void SetFilePermission(string filePath,string userName)
            {
                FileInfo fi = new FileInfo(filePath);
                FileSecurity fileSecurity = fi.GetAccessControl();
                fileSecurity.AddAccessRule
                    (new FileSystemAccessRule
                        (userName, FileSystemRights.FullControl,
                        AccessControlType.Allow));
                fi.SetAccessControl(fileSecurity);
            }

    C#设置账户对文件的访问权限为完全访问

            /// <summary>
            /// 将账户对文件夹的访问权限设置为完全访问
            /// </summary>
            /// <param name="folderPath">文件夹路径</param>
            /// <param name="userName">账户名</param>
            private void SetFolderPermission(string folderPath,string userName)
            {
                DirectoryInfo diInfo = 
                    new DirectoryInfo(folderPath);
                DirectorySecurity dirSecurity = diInfo.GetAccessControl();
                dirSecurity.AddAccessRule
                    (new FileSystemAccessRule
                        (userName, FileSystemRights.FullControl, 
                        AccessControlType.Allow));
                diInfo.SetAccessControl(dirSecurity);
            }

  • 相关阅读:
    cp文件夹
    当@PathVariable遇上中文和点
    frameset框架样式 加边框
    页面显示滑动条样式
    109.110.100.56 samba用户名 PAS, 密码 111111
    后台访问记录
    后台处理excel下载输出流
    ul li排版 左右对齐
    社保卡补办
    删除表 (truncate 、delete 、drop)
  • 原文地址:https://www.cnblogs.com/ice-/p/6165801.html
Copyright © 2020-2023  润新知