0

I am writing a provider hosted SharePoint 2013 application. I'm using SharePoint online.

Since the people picker isn't supported in this scenario, I need to build my own. I found the SearchPrincipals method. That seems like exactly what I'm looking for, but no matter what I try, the method is returning with 0 results.

What little information I've found around this method suggests that the problem is usually a permissions issue, but the user that I'm logged in as is a Site Collection Administrator (ClientContext.Web.CurrentUser.IsSiteAdmin is true), so that shouldn't be the case with me.

I've tried passing in virtually every combination of PrincipalType and PrincipalSource, even ones that didn't make sense. I've also tried passing in ClientContext.Web.SiteUsers for the scope, and also null, both of which I've seen used in my searches, and that didn't turn up any results either.

Any help would be appreciated!

4

1 回答 1

0

我想到了。CSOM ClientContext(客户端对象模型)允许开发人员进行多个——不相关的——查询。它将这些查询排队并在ExecuteQuery被调用之前不执行它们。即使SearchPrincipals是类外的静态方法Utility,它仍然会将方法调用转换为查询并将其排队。该方法将始终返回一个空集合,但是一旦您调用ExecuteQueryClientContext该集合就会被搜索结果填充。

此外,我之后立即遇到的另一个问题是,当我调用ExecuteQuery. 事实证明,之前执行的代码将一些查询排队,但它从未执行过它们,所以当我调用 时ExecuteQuery,它也执行了这些查询,其中一个出错了。如果您遇到意外错误,最好查看是否还有其他排队查询尚未执行。您可以检查布尔属性HasPendingRequest来帮助确定这一点。

希望这个答案可以节省其他人很多时间!

于 2013-06-20T11:39:33.450 回答