How to create shared folder in C# with read only access? I see this example, but it gives write access too
Asked
Active
Viewed 3,791 times
2 Answers
3
See this link Working with Shared Folders
IWHSInfo2 info = new WHSInfoClass();
IShareInfo2 share = info.CreateShare("SharedFolderName", "SharedFolderDescription", 0);
WHSUserPermission perm1 = new WHSUserPermission();
perm1.userName = "User1";
perm1.permission = WHSSharePermissions.WHS_SHARE_READ_ONLY;
WHSUserPermission perm2 = new WHSUserPermission();
perm2.userName = "User2";
perm2.permission = WHSSharePermissions.WHS_SHARE_READ_WRITE;
Array permsArray = Array.CreateInstance(typeof(WHSUserPermission), 2);
permsArray.SetValue(perm1, 0);
permsArray.SetValue(perm2, 1);
share.SetPermissions(permsArray);
Bye.

RRUZ
- 134,889
- 20
- 356
- 483
-
yea, but how to set read permissions for all users without setting permission for each user? I just need to reset Allow other users to change files checkbox – Arsen Mkrtchyan Aug 27 '09 at 14:35
-
1use the everyone user and give them read only, or if this is a web set then the aspnet user or which user the app pool the web site is running under read only. – gjutras Aug 27 '09 at 14:44
1
Try this:
File.SetAttributes("C:\Path\To\Folder", FileAttributes.ReadOnly);

Mr. Smith
- 5,489
- 11
- 44
- 60
-
no, unfortunately it doesn't help, it is not setting sharing access, and than I need to change directory sharing access not file read-only access – Arsen Mkrtchyan Aug 27 '09 at 14:29
-
You can use the above code to set attributes for a file OR folder, not just a file. – Mr. Smith Aug 27 '09 at 14:45
-
yea but it sets not sharing attribute, but file read only attribute isn't it? – Arsen Mkrtchyan Aug 28 '09 at 05:02
-
Yes, I tried it too, it does set the folder's read only attribute, but not the sharing attribute. +1 for a very interesting question, definitely going to watch this. – Mr. Smith Aug 28 '09 at 05:05