我正在使用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();
获取所需信息的正确方法是什么?
您可以使用GroupCollection.GetByName或GetById检索现有组,然后检索组合所有者。
using (var context = new ClientContext("sit url"))
{
context.Credentials = credentials;
var groupOwner = context.Web.SiteGroups.GetByName("GroupName");
ctx.ExecuteQuery();
}
我以一种非常奇怪的方式解决了这个问题。代码是这样的:
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方法来获取所有者的对象。我不知道为什么。但它的确有效。