如何使用客户端对象模型将SharePoint组添加为组所有者?
如果要创建组并添加组所有者和默认用户,可以使用以下代码:如何使用客户端对象模型将SharePoint组添加为组所有者?,sharepoint,Sharepoint,如果要创建组并添加组所有者和默认用户,可以使用以下代码: string siteUrl = "https://server/sites/sitename"; ClientContext clientContext = new ClientContext(siteUrl); Web web = clientContext.Web; GroupCreationInformation groupCreationInfo = new GroupCreationInformation(); groupC
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组“技术支持”添加为组所有者,代码应该是什么?使用或方法从站点检索现有组,然后设置其值,例如:
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();
}
谢谢瓦迪姆。我试过GetById(),成功了。我试过GetByName()不起作用,我想那是因为我在VS2010中试过了。我将在VS 2013中稍后尝试。但我认为这就是解决方案。没错,GroupCollection.GetByName是在SharePoint 2013中引入的CSOM APII尝试投票,但它需要注册,并且找不到链接的位置。