C # Modify the permissions for a file or folder, and introduce specific code that adds full control permissions for the specified user and user group
//Add the Full Control permission for the "everyone,users" user group to the Excel file FileInfo fi = new FileInfo (Excelpath); System.Security.AccessControl.FileSecurity filesecurity = fi. GetAccessControl (); Filesecurity.addaccessrule (New FileSystemAccessRule ("Everyone", Filesystemrights.fullcontrol, Accesscontroltype.allow)); Filesecurity.addaccessrule (New FileSystemAccessRule ("Users", Filesystemrights.fullcontrol, Accesscontroltype.allow)); Fi. Setaccesscontrol (FileSecurity); Add Full Control permissions for the "everyone,users" user group to the directory where the Excel files are located DirectoryInfo di = new DirectoryInfo (Path.getdirectoryname (Excelpath)); System.Security.AccessControl.DirectorySecurity dirsecurity = di. GetAccessControl (); Dirsecurity.addaccessrule (New FileSystemAccessRule ("Everyone", Filesystemrights.fullcontrol, Accesscontroltype.allow)); Dirsecurity.addaccessrule (New FileSystemAccessRule ("Users", Filesystemrights.fullcontrol, Accesscontroltype.allow )); Di. Setaccesscontrol (dirsecurity);