到目前为止,我已经阅读了很多文章,试图弄清楚如何打破库文件夹的继承,然后添加权限。例如,我有一个名为DIST0000的库,我创建了一个名为'Folder1'的文件夹,我想以编程方式设置'Folder1'的权限,因为我有很多很多文件夹。我不是很好的共享点或C#程序员,我只想弄明白。 :)
可以这样做吗?
如何?
提前致谢:)
答案 0 :(得分:0)
// get a reference to the folder (this assumes path points to a valid folder)
SPFolder folder = SharePointConfiguration.Site.GetFolder(path);
// get a reference to the Sharepoint group collection
SPGroupCollection spc = SharePointConfiguration.Site.SiteGroups;
// get a reference to the group who’s permissions you want to modify for the folder above
SPGroup group = spc[groupName];
// create a role assignment from the group reference
SPRoleAssignment roleAssignment = new SPRoleAssignment((SPPrincipal)group);
// break role inheritance for folders/files because they will be having permissions separate from their parent file/folder
folder.Item.BreakRoleInheritance(true);
// update the role assignments for the group by adding the permissionSet “TestPermissionLevel” which is a custom
// permissionset I created manually…you can easily use any of the built-in permission sets
roleAssignment.RoleDefinitionBindings.Add(SharePointConfiguration.Site.RoleDefinitions["Test Permission Level"]);
// apply the new roleassignment to the folder. You can do this at the listitem level if desired (i.e. this could be SPfile.Item…. instead of SPFolder.Item)
folder.Item.RoleAssignments.Add(roleAssignment);