2

Currently I'm using Server Side Object Model in web part

var srchResults = profileManager.GetEnumerator();
while (SrchResults.MoveNext()){//Code here}

But it takes a lot of time because the users are near about 3000 or more and I have to show them on search. For example- If I have searched with Letter N then result should show all the users whose Last Name start with letter N. It will take 12 second to show result.

please suggest any other option to retrieve users in less time like Rest,CSOM. Please share Answer and articles. because I want to use that code in Web part

Actually I want to reduce delay.

Is delay will reduce,if I used SharePoint Client Object Modal (CSOM) in web part?

1 Answer 1

3

You need to go with People search, instead fetching all users at once. This also fits your requirements for filtering, you can construct different KQL queries for filtering.

Sample code fetching all users using client object model:

var ctx = new ClientContext("https://sp.sharepoint.com/sites/dev");
var keywordQuery = new KeywordQuery(ctx);
keywordQuery.QueryText = "*";
keywordQuery.SourceId = new Guid("B09A7990-05EA-4AF9-81EF-EDFAB16C4E31");
keywordQuery.RowLimit = 100;
var searchExecutor = new SearchExecutor(ctx);
var results = searchExecutor.ExecuteQuery(keywordQuery);
ctx.ExecuteQuery();  

Please note, that search results are paged, and for speed and performance it's strongly recommended to implement paging.
For server object model you can use:

using (SPSite siteCollection = new SPSite("<serverRelativeUrl>")) 
{
    KeywordQuery keywordQuery = new KeywordQuery(siteCollection);
    keywordQuery.QueryText = "*";
    keywordQuery.SourceId = new Guid("B09A7990-05EA-4AF9-81EF-EDFAB16C4E31");
    SearchExecutor searchExecutor = new SearchExecutor(); 
    ResultTableCollection resultTableCollection = searchExecutor.ExecuteQuery(keywordQuery); 
    resultTableCollection = resultTableCollection.Filter("TableType", KnownTableTypes.RelevantResults); 
    ResultTable resultTable = resultTableCollection.FirstOrDefault(); 
    DataTable dataTable = resultTable.Table; 
} 

Additional resources:

Using the SharePoint 2013 search Query APIs
SharePoint Online : Working with People Search and User Profiles
Keyword Query Language (KQL) syntax reference

4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.