|
-
Mar 11th, 2010, 12:57 PM
#1
Applying file permissions from .NET code
Hi
I have an application that is writing a comma separated values file. How would I go about altering the permissions of that file from .NET - for example to give read-only permissions to a particular active directory group?
Thanks
Duncan
-
Mar 11th, 2010, 12:59 PM
#2
Re: Applying file permissions from .NET code
Are you looking to do this with the readonly attribute, or actually with the ACL?
-
Mar 11th, 2010, 04:03 PM
#3
Re: Applying file permissions from .NET code
With the ACL.
What I'm hoping for is:
Europe\FundAccountants read-only
Europe\TransferAgency read-write
Public - no access
-
Mar 11th, 2010, 04:14 PM
#4
Re: Applying file permissions from .NET code
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Mar 11th, 2010, 04:15 PM
#5
Re: Applying file permissions from .NET code
I'm not so sure with active directory as I haven't ever had to program against it since my software is generally of the single user commercial client type. However I did have a need to set ACL for a given folder and I used this code. I *think* it could be adapted to work with an AD group, just the same as it works with a built in users group. If not hopefully it will get you in the right direction.
Code:
Imports System.Security.AccessControl
Imports System.IO
Private Function SetUserAccess(ByVal FolderPath As String) As Boolean
Try
Dim myDirectorySecurity As System.Security.AccessControl.DirectorySecurity = System.IO.Directory.GetAccessControl(FolderPath)
Dim UsersGroupIdentifier As New Security.Principal.SecurityIdentifier(Security.Principal.WellKnownSidType.BuiltinUsersSid, Nothing)
Dim myAccessRule As New FileSystemAccessRule(UsersGroupIdentifier, _
FileSystemRights.FullControl, _
InheritanceFlags.ObjectInherit Or _
InheritanceFlags.ContainerInherit, _
PropagationFlags.InheritOnly, _
AccessControlType.Allow)
myDirectorySecurity.AddAccessRule(myAccessRule)
Directory.SetAccessControl(FolderPath, myDirectorySecurity)
Return True
Catch ex As Exception
'LOG EXCEPTION HERE
Return False
End Try
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|