Colin DeClue
Colin DeClue

Reputation: 2244

Something like SiteUserInfoList but for all sharepoint users

I'm trying to build a people-picker like tool in a sharepoint 2013 provider-hosted app. Originally, I was using Utility.ResolvePrincipal, which gives me access to any user in sharepoint, but it only gives me one user at a time (which isn't what I want). Then, I tried to use Utility.SearchPrincipals, but that never gave me any results. So then I tried using Web.SiteUserInfoList, but that only gives me access to users of my site, rather than all of sharepoint. Is there something I can use similar to SiteUserInfoList but which returns any user in sharepoint, rather than just my site? Here's what I have using SiteUserInfoList:

var camlQuery = new CamlQuery();
    camlQuery.ViewXml = @"<View>
                            <Query>
                                <Where>
                                    <Contains>
                                        <FieldRef Name='Title'/>
                                        <Value Type='Text'>" + nameStart + @"</Value>
                                    </Contains>
                                </Where>
                            </Query>
                        </View>";
    var users = _clientContext.Web.SiteUserInfoList.GetItems(camlQuery);
    _clientContext.Load(users, u => u.Include(item => item["Title"], item => item["Name"], item => item.DisplayName));
    _clientContext.ExecuteQuery();

Upvotes: 3

Views: 1365

Answers (1)

you could try to search for your users with REST.

Your URL would look something like this:

var url = string.Format("http://yoursite/_api/search/query?querytext='AccountName:{0}*'&sourceid='B09A7990-05EA-4AF9-81EF-EDFAB16C4E31'&selectproperties='PictureURL,AccountName'", nameStart);

(sourceid='B09A7990-05EA-4AF9-81EF-EDFAB16C4E31' points to content-class:STSPeople)

Upvotes: 0

Related Questions