Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error trying to set directory permissions

Status
Not open for further replies.

tmar

MIS
Mar 24, 2007
62
US
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
 
I found the issue. The variable given to the sub didn't have a type assigned to it. I changed "Private Sub userperm(ByVal userid)" to "Private Sub userperm(ByVal userid as String)
" and it worked.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top