VB.NET Set Folder Permission / C#
Set Folder Permission
Allow/Deny
In this snippet we create a new directory and set the permission of it to Fullcontrol using ACL.
VB code
Private Shared Sub ChangePermissionOfDir()
'Folder
Dim NewDirectory As DirectoryInfo = Directory.CreateDirectory("C:\Test001")
Dim dSecurity As DirectorySecurity = NewDirectory.GetAccessControl()
Dim fAccess As New FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Deny)
dSecurity.AddAccessRule(fAccess)
NewDirectory.SetAccessControl(dSecurity)
End Sub
C# code
private static void ChangePermissionOfDir()
{
//Folder
DirectoryInfo NewDirectory = Directory.CreateDirectory("C:\\Test001");
DirectorySecurity dSecurity = NewDirectory.GetAccessControl();
FileSystemAccessRule fAccess = new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Deny);
dSecurity.AddAccessRule(fAccess);
NewDirectory.SetAccessControl(dSecurity);
}
Set Folder Permission
Allow/Deny
In this snippet we create a new directory and set the permission of it to Fullcontrol using ACL.
VB code
Private Shared Sub ChangePermissionOfDir()
'Folder
Dim NewDirectory As DirectoryInfo = Directory.CreateDirectory("C:\Test001")
Dim dSecurity As DirectorySecurity = NewDirectory.GetAccessControl()
Dim fAccess As New FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Deny)
dSecurity.AddAccessRule(fAccess)
NewDirectory.SetAccessControl(dSecurity)
End Sub
C# code
private static void ChangePermissionOfDir()
{
//Folder
DirectoryInfo NewDirectory = Directory.CreateDirectory("C:\\Test001");
DirectorySecurity dSecurity = NewDirectory.GetAccessControl();
FileSystemAccessRule fAccess = new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Deny);
dSecurity.AddAccessRule(fAccess);
NewDirectory.SetAccessControl(dSecurity);
}
0 comments:
Post a Comment