Unable to set write permission on file

501 views Asked by At

I want to create a file and give a user write permission.

IO.File.Create(Path & "\test.json")
Dim fs As Security.AccessControl.FileSecurity = IO.File.GetAccessControl(Path & "\test.json")
Dim far As Security.AccessControl.FileSystemAccessRule = New Security.AccessControl.FileSystemAccessRule("DOMAIN\USER", Security.AccessControl.FileSystemRights.WriteData, Security.AccessControl.AccessControlType.Allow)
fs.AddAccessRule(far)

When I check the Security tab for this file, I see no changes. VS2015 output window does not show any exceptions. VS2015 is running as Administrator.

I used this for reference: https://msdn.microsoft.com/en-us/library/d49cww7f(v=vs.110).aspx

1

There are 1 answers

1
competent_tech On

All you have changed in your code is the in-memory file security. In order to apply these changes to the file, you must call SetAccessControl.

For example:

File.SetAccessControl(Path & "\test.json", fs)