private void ModifyFilePermission(string path, string user, FileType filetype) { if (filetype == FileType.File) { FileInfo fileinfo = new FileInfo(path); FileSecurity fileSecurity = fileinfo.GetAccessControl(); fileSecurity.AddAccessRule(new FileSystemAccessRule(user, FileSystemRights.FullControl, AccessControlType.Allow)); fileinfo.SetAccessControl(fileSecurity); } else if (filetype == FileType.Directory) { DirectoryInfo di = new DirectoryInfo(path); DirectorySecurity dirSecurity = di.GetAccessControl(); dirSecurity.AddAccessRule(new FileSystemAccessRule(user, FileSystemRights.FullControl, AccessControlType.Allow)); di.SetAccessControl(dirSecurity); } } enum FileType { Directory, File }
时间: 2024-10-13 11:39:21