按日期时间对 DirectorySearcher 查询的结果进行排序 [英] Sorting the results of a DirectorySearcher query by DateTime

查看:54
本文介绍了按日期时间对 DirectorySearcher 查询的结果进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

// Declare new DirectoryEntry and DirectorySearcher
DirectoryEntry domainRoot = new DirectoryEntry("LDAP://rootDSE");
string rootOfDomain = domainRoot.Properties["rootDomainNamingContext"].Value.ToString();
DirectorySearcher dsSearch = new DirectorySearcher(rootOfDomain);

// Set the properties of the DirectorySearcher
dsSearch.Filter = "(objectClass=Computer)";
dsSearch.PropertiesToLoad.Add("whenCreated");
dsSearch.PropertiesToLoad.Add("description");
dsSearch.PropertiesToLoad.Add("operatingSystem");
dsSearch.PropertiesToLoad.Add("name");

// Execute the search
SearchResultCollection computersFound = dsSearch.FindAll();

我想按 whenCreated 属性按降序对结果进行排序,以便最新的计算机对象位于顶部.

I want to sort the results by the whenCreated property in descending order, so that the newest computer objects are at the top.

我不能简单地做:

SortOption sortedResults = new SortOption("whenCreated", SortDirection.Descending);
dsSearch.Sort = sortedResults;

因为服务器返回错误(http://social.technet.microsoft.com/Forums/en-US/winserverDS/thread/183a8f2c-0cf7-4081-9110-4cf41b91dcbf/)

because the server returns an error (http://social.technet.microsoft.com/Forums/en-US/winserverDS/thread/183a8f2c-0cf7-4081-9110-4cf41b91dcbf/)

对此进行排序的最佳方法是什么?

What is the best way to sort this?

推荐答案

您可以按照 MSDN 这里:

You can do it server side as mentioned in MSDN here:

      new DirectorySearcher(entry)
      {
        Sort = new SortOption("cn", SortDirection.Ascending),
        PropertiesToLoad = {"cn"}
      };

链接的问题线程已解决:

The linked issue thread is solved:

我们在 AD Windows 2008 R2 上有同样的问题

We have the same issue on AD Windows 2008 R2

  • 已应用 kb977180-v2 http://support.microsoft.com/kb/977180
  • 并添加了密钥HKLM\System\CurrentControlSet\Services\NTDS\Parameters
  • 添加字符串值DSA 启发式"
  • 将值设置为 000000000001
  • 重启
  • 此问题解决后

这篇关于按日期时间对 DirectorySearcher 查询的结果进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆