I need to display all the users from the User Profile Service with some basic properties like name email in a web part in sharepoint 2013.
Please help on this.
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityI need to display all the users from the User Profile Service with some basic properties like name email in a web part in sharepoint 2013.
Please help on this.
Use search to get all the users. Make sure you define some kind of sorting.
C# on-prem sample:
private static DataTable GetPeople(SPSite spSite, string queryText)
{
var keywordQuery = new KeywordQuery(spSite)
{
QueryText = queryText,
KeywordInclusion = KeywordInclusion.AllKeywords,
HiddenConstraints = "scope:" + "\"People\"",
ResultTypes = ResultType.RelevantResults,
RankingModelId = "D9BFB1A1-9036-4627-83B2-BBD9983AC8A1"
};
keywordQuery.RowLimit = 200;
keywordQuery.SelectProperties.Add("AccountName");
keywordQuery.SelectProperties.Add("UserProfile_GUID");
keywordQuery.SelectProperties.Add("PreferredName");
keywordQuery.SelectProperties.Add("WorkEmail");
keywordQuery.SelectProperties.Add("PictureURL");
keywordQuery.SelectProperties.Add("MobilePhone");
ResultTableCollection resultTableCol = keywordQuery.Execute();
ResultTable resultTable = resultTableCol[ResultType.RelevantResults];
var resultsDataTable = new DataTable
{
TableName = "Results"
};
resultsDataTable.Load(resultTable, LoadOption.OverwriteChanges);
return resultsDataTable;
}
Insert a Search Results web part.
Edit the web part, click Change Query
. In the Select a Query
dropdown, select Local People Results (System)
. In the Query Text
box, enter contentclass=people
. Go to the Test tab to make sure that your query will populate the results you're looking for, then save everything.
You can also add additional filters, if you'd like. You can also add refiners, and sort. Just play around with the setting a bit.