kamagra how much to take

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:

  1. public static DataTable BuildDepartmentEmployees(string url, string deptName, int queryLimit)
  2. {
  3. using (var resultĀ  = new DataTable())
  4. {
  5. using (var site = new SPSite(url))
  6. {
  7. using (var query = new KeywordQuery(site))
  8. {
  9. query.ResultTypes = ResultType.RelevantResults;
  10. query.EnableStemming = true;
  11. query.TrimDuplicates = true;
  12. query.StartRow = 0;
  13. query.RowLimit = queryLimit;
  14. string str =
  15. query.QueryText = string.Format("scope:\"{0}\"", "people") + string.Format(" department:\"{0}\"", deptName);
  16. query.SortList.Add("Rank", SortDirection.Ascending);
  17. query.SelectProperties.Add("AccountName");
  18. query.SelectProperties.Add("FirstName");
  19. query.SelectProperties.Add("LastName");
  20. query.SelectProperties.Add("JobTitle");
  21. query.SelectProperties.Add("WorkEmail");
  22. query.SelectProperties.Add("Department");
  23. query.SelectProperties.Add("WorkPhone");
  24. query.SelectProperties.Add("Fax");
  25. query.SelectProperties.Add("UserProfile_GUID");
  26. query.SelectProperties.Add("UserName");
  27. query.SelectProperties.Add("PreferredName");
  28. query.SelectProperties.Add("OfficeNumber");
  29. query.SelectProperties.Add("MobilePhone");
  30. query.SelectProperties.Add("PIctureURL");
  31. query.SelectProperties.Add("WebSite");
  32. query.SelectProperties.Add("PublicSiteRedirect");
  33. using (ResultTable reader = query.Execute()[ResultType.RelevantResults])
  34. {
  35. result.Load(reader, LoadOption.OverwriteChanges);
  36. }
  37. }
  38. }
  39. return result;
  40. }
  41. }
Share

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>