在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
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); } |
请发表评论