Louis

Louis

  • NA
  • 1
  • 0

Having trouble with FileSecurity.AddAccessRule

Jun 25 2007 5:59 PM
I'm having trouble with a piece of VB.NET code having to pertain to setting permissions on a folder I've created. I've seen this code a bunch of other places in the same format, but it just doesn't work for me. This part of the app is a sub routine that is adding permissions to a folder that is programatically created in a share on a file server for home drives.

Private Sub AddFileSecurity(ByVal fileName As String, ByVal account As String, _
ByVal rights As FileSystemRights, ByVal controlType As AccessControlType)

' Get a FileSecurity object that represents the

' current security settings.

Try

Dim fSecurity As FileSecurity = File.GetAccessControl(fileName)

fSecurity.AddAccessRule(
New FileSystemAccessRule(account, rights, controlType))

fSecurity.AddAccessRule(New FileSystemAccessRule(account, rights, _
InheritanceFlags.ObjectInherit
Or InheritanceFlags.ContainerInherit, _
PropagationFlags.InheritOnly, AccessControlType.Allow))

Dim currentUser As Security.Principal.NTAccount = _
New Security.Principal.NTAccount(_ShortDomainName, _Username)

fSecurity.SetOwner(currentUser)

' Set the new access settings.

File.SetAccessControl(fileName, fSecurity)

Catch ex As Exception

MsgBox(ex.ToString)

End Try

End Sub


I'm catching "System.ArgumentException: No flags can be set" at the File.SetAccessControl line. I've already set up all my stops and checked my variables and they're in the correct format (so I think anyways). Any help would be appreciated.


Answers (1)