DirectoryInfo.GetAccessControl : DirectoryInfo « File Directory « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Date Time
8.Development
9.Event
10.File Directory
11.Generics
12.GUI
13.Internationalization I18N
14.Language Basics
15.LINQ
16.Network Remote
17.Reflection
18.Security
19.Thread
20.Windows Presentation Foundation
21.Windows System
22.XML
23.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » File Directory » DirectoryInfoScreenshots 
DirectoryInfo.GetAccessControl
 

Imports System
Imports System.IO
Imports System.Security.AccessControl

Module DirectoryExample
    Sub Main()
        Try
            Dim DirectoryName As String = "TestDirectory"
            AddDirectorySecurity(DirectoryName, "MYDOMAIN\MyAccount", FileSystemRights.ReadData, AccessControlType.Allow)
            RemoveDirectorySecurity(DirectoryName, "MYDOMAIN\MyAccount", FileSystemRights.ReadData, AccessControlType.Allow)
        Catch As Exception
            Console.WriteLine(e)
        End Try
        Console.ReadLine()

    End Sub
    Sub AddDirectorySecurity(ByVal FileName As String, ByVal Account As String, ByVal Rights As FileSystemRights, ByVal ControlType As AccessControlType)
        Dim dInfo As New DirectoryInfo(FileName)
        Dim dSecurity As DirectorySecurity = dInfo.GetAccessControl()
        dSecurity.AddAccessRule(New FileSystemAccessRule(Account, Rights, ControlType))
        dInfo.SetAccessControl(dSecurity)
    End Sub
    Sub RemoveDirectorySecurity(ByVal FileName As String, ByVal Account As String, ByVal Rights As FileSystemRights, ByVal ControlType As AccessControlType)
        Dim dInfo As New DirectoryInfo(FileName)
        Dim dSecurity As DirectorySecurity = dInfo.GetAccessControl()
        dSecurity.RemoveAccessRule(New FileSystemAccessRule(Account, Rights, ControlType))
        dInfo.SetAccessControl(dSecurity)
    End Sub
End Module

   
  
Related examples in the same category
1.Create DirectoryInfo class on the specified path.
2.DirectoryInfo.Create Creates a directory.
3.DirectoryInfo.CreateSubdirectory
4.DirectoryInfo.Delete deletes this instance of a DirectoryInfo, specifying whether to delete subdirectories and files.
5.DirectoryInfo.Delete deletes this DirectoryInfo if it is empty.
6.DirectoryInfo.EnumerateDirectories Method (String, SearchOption)
7.DirectoryInfo.EnumerateDirectories returns an enumerable collection of directory information in the current directory.
8.DirectoryInfo.Exists Property gets a value indicating whether the directory exists.
9.DirectoryInfo.GetDirectories returns an array of directories in the current DirectoryInfo matching the given search criteria.
10.DirectoryInfo.GetDirectories (String, SearchOption)
11.DirectoryInfo.GetDirectories returns the subdirectories of the current directory.
12.DirectoryInfo.GetFiles returns a file list from the current directory matching the given search pattern.
13.DirectoryInfo.GetFiles returns a file list from the current directory.
14.DirectoryInfo.MoveTo moves a DirectoryInfo instance and its contents to a new path.
15.DirectoryInfo.Name Property gets the name of this DirectoryInfo instance.
16.DirectoryInfo.Parent Property gets the parent directory of a specified subdirectory.
17.DirectoryInfo.Root Property gets the root portion of a path.
18.DirectoryInfo Class Exposes instance methods for creating, moving, and enumerating through directories and subdirectories
19.Copy a directory with DirectoryInfo
20.Create and delete directory with DirectoryInfo
21.FileSystemInfo Class provides the base class for both FileInfo and DirectoryInfo objects.
ww_w__._j___a_va2s.__c__o_m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.