如何通过CSOM获得团体所有者

问题描述 投票:0回答:2

我正在使用Sharepoint Online和CSOM,我需要获得特定组的所有者。

我试图从ClientContext加载数据,并得到一个带有“未知错误”消息的异常。

这是我试过的代码。

MC.ClientContext context = new SPClient.ClientContext("sit url");
MC.Group group = context.Web.SiteGroups.GetById("group id");
context.Load(group, x => x.Owner);
await context.ExecuteQueryAsync();

获取所需信息的正确方法是什么?

c# csom
2个回答
0
投票

您可以使用GroupCollection.GetByNameGetById检索现有组,然后检索组合所有者。

using (var context = new ClientContext("sit url"))
{
    context.Credentials = credentials;

    var groupOwner = context.Web.SiteGroups.GetByName("GroupName"); 
    ctx.ExecuteQuery();     
}

0
投票

我以一种非常奇怪的方式解决了这个问题。代码是这样的:

ClientContext context = new SPClient.ClientContext("sit url");
Group group = context.Web.SiteGroups.GetById("group id");
context.Load(group, x => x.Owner.PrincipalType,  x => x.Owner.LoginName);
await context.ExecuteQueryAsync();
context.Load(group.Owner);
await context.ExecuteQueryAsync();

我需要两次调用ExecuteQuery方法来获取所有者的对象。我不知道为什么。但它的确有效。

© www.soinside.com 2019 - 2024. All rights reserved.