I tried to replicate some code I found on the web regarding setting directory permissions but am having an error. The code is below and all of the code inside the parenthesis of "folderacl.AccessRule(".... to the ")" at the end is underlined as error.
Private Sub userperm(ByVal userid)
Dim folderinfo As IO.DirectoryInfo = New IO.DirectoryInfo(mfolder)
Dim folderacl As New DirectorySecurity
folderacl = folderinfo.GetAccessControl
folderacl.AddAccessRule(New FileSystemAccessRule(userid, FileSystemRights.Read, _
InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit, _
PropagationFlags.None, AccessControlType.Allow))
folderinfo.SetAccessControl(folderacl)
End Sub
The error on the Error List page is as follows:
Error 1 Overload resolution failed because no accessible 'New' can be called without a narrowing conversion:
'Public Sub New(identity As String, fileSystemRights As System.Security.AccessControl.FileSystemRights, inheritanceFlags As System.Security.AccessControl.InheritanceFlags, propagationFlags As System.Security.AccessControl.PropagationFlags, type As System.Security.AccessControl.AccessControlType)': Argument matching parameter 'identity' narrows from 'Object' to 'String'.
'Public Sub New(identity As System.Security.Principal.IdentityReference, fileSystemRights As System.Security.AccessControl.FileSystemRights, inheritanceFlags As System.Security.AccessControl.InheritanceFlags, propagationFlags As System.Security.AccessControl.PropagationFlags, type As System.Security.AccessControl.AccessControlType)': Argument matching parameter 'identity' narrows from 'Object' to 'System.Security.Principal.IdentityReference'. P:\Mas 500 Client\VB\HRMaster\HRMaster\frmMain.vb 88 33 HRMaster
Private Sub userperm(ByVal userid)
Dim folderinfo As IO.DirectoryInfo = New IO.DirectoryInfo(mfolder)
Dim folderacl As New DirectorySecurity
folderacl = folderinfo.GetAccessControl
folderacl.AddAccessRule(New FileSystemAccessRule(userid, FileSystemRights.Read, _
InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit, _
PropagationFlags.None, AccessControlType.Allow))
folderinfo.SetAccessControl(folderacl)
End Sub
The error on the Error List page is as follows:
Error 1 Overload resolution failed because no accessible 'New' can be called without a narrowing conversion:
'Public Sub New(identity As String, fileSystemRights As System.Security.AccessControl.FileSystemRights, inheritanceFlags As System.Security.AccessControl.InheritanceFlags, propagationFlags As System.Security.AccessControl.PropagationFlags, type As System.Security.AccessControl.AccessControlType)': Argument matching parameter 'identity' narrows from 'Object' to 'String'.
'Public Sub New(identity As System.Security.Principal.IdentityReference, fileSystemRights As System.Security.AccessControl.FileSystemRights, inheritanceFlags As System.Security.AccessControl.InheritanceFlags, propagationFlags As System.Security.AccessControl.PropagationFlags, type As System.Security.AccessControl.AccessControlType)': Argument matching parameter 'identity' narrows from 'Object' to 'System.Security.Principal.IdentityReference'. P:\Mas 500 Client\VB\HRMaster\HRMaster\frmMain.vb 88 33 HRMaster