在CSOM(C#)中,我正在创建一个子网站,并为Owners,Members和Vistors创建SharePoint组。
共享时,Vistors应为默认组。在UI中,您可以通过在组设置下选择“生成默认组”来将Vistors组设置为默认值。
但是你如何在CSOM中做到这一点?
以下是我目前创建群组的代码
private void SetSecurity(Web web)
{
CreateGroup($"Besøgende på {web.Title}", $"Denne gruppe giver læserettighed til {web.Title} sitet", AssociatedGroup.Vistors, web);
CreateGroup($"Medlemmer af {web.Title}", $"Denne gruppe giver skriverettighed til {web.Title} sitet", AssociatedGroup.Members, web);
CreateGroup($"Ejere af {web.Title}", $"Denne gruppe giver fuld kontrol til {web.Title} sitet", AssociatedGroup.Owners, web);
SpClientContext.ExecuteQuery();
}
private enum AssociatedGroup
{
Owners,
Members,
Vistors
}
private void CreateGroup(string title, string description, AssociatedGroup associatedGroup, Web web)
{
var groupCreation = new GroupCreationInformation();
groupCreation.Title = title;
groupCreation.Description = title;
var group = web.SiteGroups.Add(groupCreation);
var collRoleDefinitionBinding = new RoleDefinitionBindingCollection(SpClientContext);
switch (associatedGroup)
{
case AssociatedGroup.Owners:
web.AssociatedOwnerGroup = group;
web.AssociatedOwnerGroup.Update();
var adminRoleDefinition = web.RoleDefinitions.GetByType(RoleType.Administrator);
collRoleDefinitionBinding.Add(adminRoleDefinition);
break;
case AssociatedGroup.Members:
web.AssociatedMemberGroup = group;
web.AssociatedMemberGroup.Update();
var contributerDefinition = web.RoleDefinitions.GetByType(RoleType.Contributor);
collRoleDefinitionBinding.Add(contributerDefinition);
break;
case AssociatedGroup.Vistors:
web.AssociatedVisitorGroup = group;
web.AssociatedVisitorGroup.Update();
var vistorDefinition = web.RoleDefinitions.GetByType(RoleType.Reader);
collRoleDefinitionBinding.Add(vistorDefinition);
break;
}
web.RoleAssignments.Add(group, collRoleDefinitionBinding);
group.Update();
web.Update();
}
我尝试将访问者群体设置为AssociatedMemberGroup,但是没有给出正确的结果,因为在共享UI时,UI将映射到“可编辑”选项。
case AssociatedGroup.Vistors:
//web.AssociatedVisitorGroup = group;
web.AssociatedMemberGroup = group;
web.AssociatedMemberGroup.Update();
var vistorDefinition = web.RoleDefinitions.GetByType(RoleType.Reader);
collRoleDefinitionBinding.Add(vistorDefinition);
break;
http://i.stack.imgur.com/J7Ljt.png
那么关于如何在CSOM中将访客群体标记为共享时的默认群组的任何建议?
答案 0 :(得分:3)
以下示例演示了如何使用CSOM API设置默认组:
public static void SetDefaultGroup(Group group)
{
var ctx = group.Context as ClientContext;
ctx.Web.AssociatedMemberGroup = group;
ctx.Web.Update();
ctx.ExecuteQuery();
}
用法
var group = ctx.Web.SiteGroups.GetById(groupId);
SetDefaultGroup(group);