sharepoint - 如何使用客户端对象模型将 SharePoint 组添加为组所有者?

标签 sharepoint

如果要创建组并添加组所有者和默认用户,可以使用以下代码:

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.GetByNameGroupCollection.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/

相关文章:

sharepoint - 用于删除 Sharepoint 文档库中超过一天的文件的脚本

sharepoint - 无法使用Sharepoint PowerShell更新列表字段属性

css - SharePoint 全局导航链接重复

jQuery <nobr> 选择器

security - 敏感数据的共享点重新身份验证

SharePoint CAML 查询 Orderby 不支持降序属性。?

asp.net-mvc - ADFS 单一注销在 Internet Explorer 10 中不起作用

c# - Sharepoint 事件接​​收器安全异常

Sharepoint:有什么方法可以获取查找列表的其他列的值吗?

database - SharePoint 数据库创建最佳实践 list 是什么样的?