gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 23:38:38 27 4
gpt4 key购买 nike

如何按个人资料属性进行搜索? 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;
}
}

关于c# - 按配置文件属性搜索用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26794553/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com