如果要创建组并添加组所有者和默认用户,可以使用以下代码:
string siteUrl = "https://server/sites/sitename";
ClientContext clientContext = new ClientContext(siteUrl);
Web web = clientContext.Web;
GroupCreationInformation groupCreationInfo = new GroupCreationInformation();
groupCreationInfo.Title = "Custom Group";
groupCreationInfo.Description = "description ...";
User owner = web.EnsureUser(@"domain\username1");
User member = web.EnsureUser(@"domain\username2");
Group group = web.SiteGroups.Add(groupCreationInfo);
group.Owner = owner;
group.Users.AddUser(member);
group.Update();
clientContext.ExecuteQuery();
我的问题是:我知道如何将用户添加为组所有者,但是如果我想将 SharePoint 组“技术支持”添加为组所有者,代码应该是什么?
最佳答案
使用 GroupCollection.GetByName或 GroupCollection.GetById从站点检索现有组然后设置 Group.Owner property 的方法其值(value),例如:
using (var ctx = new ClientContext(webUri))
{
ctx.Credentials = credentials;
var groupCreationInfo = new GroupCreationInformation
{
Title = groupName,
Description = groupDesc
};
var groupOwner = ctx.Web.SiteGroups.GetByName("Tech Support"); //get an existing group
var group = ctx.Web.SiteGroups.Add(groupCreationInfo);
group.Owner = groupOwner;
group.Update();
ctx.ExecuteQuery();
}
关于sharepoint - 如何使用客户端对象模型将 SharePoint 组添加为组所有者?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25653909/