using System; using System.IO; using System.Security.AccessControl; namespace FileSystemExample { class FileExample { public static void Main() { try { string fileName = "test.xml"; Console.WriteLine("Adding access control entry for " + fileName); // Add the access control entry to the file. AddFileSecurity(fileName, @"DomainName\AccountName", FileSystemRights.ReadData, AccessControlType.Allow); Console.WriteLine("Removing access control entry from " + fileName); // Remove the access control entry from the file. RemoveFileSecurity(fileName, @"DomainName\AccountName", FileSystemRights.ReadData, AccessControlType.Allow); Console.WriteLine("Done."); } catch (Exception e) { Console.WriteLine(e); } } // Adds an ACL entry on the specified file for the specified account. public static void AddFileSecurity(string fileName, string account, FileSystemRights rights, AccessControlType controlType) { // Get a FileSecurity object that represents the // current security settings. FileSecurity fSecurity = File.GetAccessControl(fileName); // Add the FileSystemAccessRule to the security settings. fSecurity.AddAccessRule(new FileSystemAccessRule(account, rights, controlType)); // Set the new access settings. File.SetAccessControl(fileName, fSecurity); } // Removes an ACL entry on the specified file for the specified account. public static void RemoveFileSecurity(string fileName, string account, FileSystemRights rights, AccessControlType controlType) { // Get a FileSecurity object that represents the // current security settings. FileSecurity fSecurity = File.GetAccessControl(fileName); // Remove the FileSystemAccessRule from the security settings. fSecurity.RemoveAccessRule(new FileSystemAccessRule(account, rights, controlType)); // Set the new access settings. File.SetAccessControl(fileName, fSecurity); } } }
Tuesday, 27 June 2017
FileSystemSecurity.AddAccessRule Method (FileSystemAccessRule)
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2017
(142)
-
▼
June
(45)
- Virtialise Physical Machine
- Vagrant Setup
- Vagrant File
- Vagrant
- Upgrading and Installing TFS
- Unistalling AVG E-Mail Server Edition
- TFS Permissions
- Tesseract OCR 3.0.5 Dev
- Tesseract Links
- Telnet, Console and AUX Port Passwords on Cisco Ro...
- Robocopy Folder Sync Script
- NLP LDA related links
- Network Level Authentication on Windows XP
- MySQL Password Update
- MySQL Max Pool Size
- Making a dashed line in d3
- LDAP Connection Strings
- IIS Redirect Setup
- D3 Examples
- Create your first Windows virtual machine in the A...
- Create PDF/A with Ghostscript
- Cisco Router Delete Static Entries
- Cisco Router Commands
- All ImageMagick Binaries URL
- Adding domain account email
- How to Install AntiSpam Agents in Exchange 2010
- Converting a date in MySQL from string field
- MySQL: week date range from week number in a query
- MySQL: Going from week of the year to date of the ...
- Is the Windows user ready for apt-get?
- Parse URL with jquery/ javascript?
- ASP.NET MVC - passing parameters to the controller
- Get SELECT's value and text in jQuery
- Improving Performance with Output Caching (C#)
- How to: Cache Versions of a Page Using Parameters
- How change List data to IQueryable data [duplicate]
- Fluent NHibernate Tutorial | C# Windows CRUD Example
- NHibernate: insert multiple items at once
- Process.start: how to get the output?
- Programmatically Adding Permissions to a Folder
- MySQL query String contains
- How to grant full permission to a file created by ...
- How to get username and SID for user by a domain n...
- FileSystemSecurity.AddAccessRule Method (FileSyste...
- PowerShell Get List Of Folders Shared
-
▼
June
(45)
No comments:
Post a Comment
Note: only a member of this blog may post a comment.