如何通过CSOM获取组所有者

时间:2019-04-30 02:52:19

标签: c# csom

我正在与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();

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

2 个答案:

答案 0 :(得分:0)

您可以使用GroupCollection.GetByNameGetById来检索现有的网上论坛,然后检索该网上论坛的所有者。

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

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

答案 1 :(得分: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方法两次以获取所有者的对象。 我不知道为什么但这有效。

相关问题