You are currently reviewing an older revision of this page.
Go to current version
The following code samples shows how to retrive the user profile property ex Accountname using the KeywordQuery Search

We are passing a custom property(CustomID) as a input to the KeywordQuery Search API,which in turn will fetch the Account name for the user.

                        string strAccountName = string.Empty;   
                        SPSite currentSite = new SPSite(SPContext.Current.Site.ID);
                        KeywordQuery peopleQuery = new KeywordQuery(currentSite);
                        peopleQuery.ResultsProvider = SearchProvider.SharepointSearch;
                        peopleQuery.RowLimit = 2;
                        peopleQuery.HiddenConstraints = "scope:" + "\"People\"";
                        peopleQuery.ResultTypes = ResultType.RelevantResults;
                        peopleQuery.QueryText = "CustomId:" + strCustomId;  //where CustomId will the managed property and strCustimId will be the value of the search
                        ResultTableCollection resultCollection = peopleQuery.Execute();
                        if (resultCollection.Exists(ResultType.RelevantResults))
                            ResultTable result = resultCollection[ResultType.RelevantResults];
                            DataTable tblResult = new DataTable();
                            tblResult.TableName = "CustomIdMatch";
                            tblResult.Load(result, LoadOption.OverwriteChanges);
                            if (tblResult.Rows.Count > 0)
                                strAccountName = Convert.ToString(tblResult.Rows[0]["AccountName"]);
Revert to this revision