Using the KeywordQuery Class to Get a List of Department Employees
Posted in SharePoint, SharePoint 2007 Development |Posted by 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.
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;
-
}
-
}











November 10th, 2008 at 8:39 am
[...] 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. [...]