C# 按配置文件属性搜索用户

C# 按配置文件属性搜索用户,c#,sharepoint,sharepoint-2013,C#,Sharepoint,Sharepoint 2013,如何按配置文件属性进行搜索?MSDN说使用ProfileSearchManager,但它不起作用。 我希望通过MobilePhone属性搜索用户 SPServiceContext serviceContext = SPServiceContext.GetContext(site); UserProfileManager upm = new UserProfileManager(serviceContext); ProfileSearchManager sp = ProfileSearchMana

如何按配置文件属性进行搜索?MSDN说使用ProfileSearchManager,但它不起作用。 我希望通过MobilePhone属性搜索用户

SPServiceContext serviceContext = SPServiceContext.GetContext(site);
UserProfileManager upm = new UserProfileManager(serviceContext);
ProfileSearchManager sp = ProfileSearchManager.GetProfileSearchManager(serviceContext);

string[] searchPattern = { "123" };
ProfileBase[] searchResults = sp.Search(searchPattern, ProfileSearchFlags.User);

foreach (ProfileBase profile in searchResults)
{
    Console.WriteLine(profile.DisplayName);
}
 using (SPSite site = new SPSite(siteUrl))
            {
                    using (var qRequest = new KeywordQuery(site)
                    {
                        QueryText = "MobilePhone:*" +"123" , 
                        EnableQueryRules = true,
                        EnableSorting = false, 
                        SourceId = new Guid("Enter here Result Source Guid"),
                        TrimDuplicates = false
                    })
                    { 
                        //Get properties you want here
                        qRequest.SelectProperties.Add("FirstName");
                        qRequest.SelectProperties.Add("LastName");


                        SearchExecutor e = new SearchExecutor();
                        ResultTableCollection rt = e.ExecuteQuery(qRequest);
                        var tab = rt.Filter("TableType", KnownTableTypes.RelevantResults);
                        var result = tab.FirstOrDefault();

                        DataTable resultTable = result.Table;
                    }
}