Hi @Ching Song Lim ,
Per my test, I can search the users in current sites by following code. Please make a reference
string userToFind = "userToFind"; //it may be full or partial name of the user
string webUrl = "<site url>";
string userName = "<user name>";
string password = "<password>";
SecureString passWord = new SecureString();
//creating the context of the SharePoint site
using(ClientContext clientCtx = new ClientContext(webUrl)) {
foreach(char c in password.ToCharArray())
passWord.AppendChar(c);
clientCtx.Credentials = new SharePointOnlineCredentials(userName, passWord);
clientCtx.ExecuteQuery();
//preparing the search query options
Microsoft.SharePoint.ApplicationPages.ClientPickerQuery.ClientPeoplePickerQueryParameters peoplePickerQuery = new Microsoft.SharePoint.ApplicationPages.ClientPickerQuery.ClientPeoplePickerQueryParameters();
peoplePickerQuery.AllowEmailAddresses = true;
peoplePickerQuery.AllowMultipleEntities = false;
peoplePickerQuery.ForceClaims = false;
peoplePickerQuery.MaximumEntitySuggestions = 60;
peoplePickerQuery.PrincipalType = Microsoft.SharePoint.Client.Utilities.PrincipalType.All;
peoplePickerQuery.PrincipalSource = Microsoft.SharePoint.Client.Utilities.PrincipalSource.All;
peoplePickerQuery.QueryString = userToFind;
peoplePickerQuery.AllUrlZones = true;
peoplePickerQuery.SharePointGroupID = 0;
peoplePickerQuery.WebApplicationID = new Guid("00000000-0000-0000-0000-000000000000");
//Using peoplepicker webservice and searchquery getting the matched userInformations from SharePoint
ClientResult < String > resultData = Microsoft.SharePoint.ApplicationPages.ClientPickerQuery.ClientPeoplePickerWebServiceInterface.ClientPeoplePickerSearchUser(clientCtx, peoplePickerQuery);
clientCtx.ExecuteQuery();
}
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.