Using the KeywordQuery Class to Get a List of Department Employees
Along the same lines as this post, once one has located the relevant department that they desire from a collection, how is it possible to use that department string name in order to get a list of the relevant employees? As we used the KeywordQuery class the last time, we are going to take the same approach in order to return a new DataTable with those values.
Here is the code in order to execute that:
C#:
-
public static DataTable BuildDepartmentEmployees(string url, string deptName, int queryLimit)
-
{
-
{
-
{
-
{
-
query.ResultTypes = ResultType.RelevantResults;
-
query.EnableStemming = true;
-
query.TrimDuplicates = true;
-
query.StartRow = 0;
-
query.RowLimit = queryLimit;
-
string str =
-
query.QueryText = string.Format("scope:\"{0}\"", "people") + string.Format(" department:\"{0}\"", deptName);
-
query.SortList.Add("Rank", SortDirection.Ascending);
-
query.SelectProperties.Add("AccountName");
-
query.SelectProperties.Add("FirstName");
-
query.SelectProperties.Add("LastName");
-
query.SelectProperties.Add("JobTitle");
-
query.SelectProperties.Add("WorkEmail");
-
query.SelectProperties.Add("Department");
-
query.SelectProperties.Add("WorkPhone");
-
query.SelectProperties.Add("Fax");
-
query.SelectProperties.Add("UserProfile_GUID");
-
query.SelectProperties.Add("UserName");
-
query.SelectProperties.Add("PreferredName");
-
query.SelectProperties.Add("OfficeNumber");
-
query.SelectProperties.Add("MobilePhone");
-
query.SelectProperties.Add("PIctureURL");
-
query.SelectProperties.Add("WebSite");
-
query.SelectProperties.Add("PublicSiteRedirect");
-
using (ResultTable reader = query.Execute()[ResultType.RelevantResults])
-
{
-
result.Load(reader, LoadOption.OverwriteChanges);
-
}
-
}
-
}
-
return result;
-
}
-
}
1 Comment »
RSS feed for comments on this post. TrackBack URL





















Articles & Research
SharePoint Architecture
Personal/Off-Topic
Latest Free SharePoint Software
SecureCenter For SharePoint
SharePoint Security Assurance Program™
Free Online SharePoint Security Tools
Online SharePoint Security Health Assessment
Article Or Research Filed Under 
[...] Using the KeywordQuery Class to Get a List of Department Employees (Adam Buenz)Along the same lines as this post, once one has located the relevant department that they desire from a collection, how is it possible to use that department string name in order to get a list of the relevant employees? As we used the KeywordQuery class the last time, we are going to take the same approach in order to return a new DataTable with those values. [...]
Pingback by SharePoint Daily for November 10, 2008 - SharePoint Daily — November 10, 2008 @ 8:39 am