分選的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
屬性對結果進行排序,使最新的計算機對象是在頂部。
我不能簡單地做:
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 /)
對此進行排序的最佳方法是什麼?
一般情況下,我要堅持像AD上面的一個作爲服務器端各種各樣的解決方案都是資源密集型和故障易髮結果集較大。 – 2012-04-15 20:09:26
謝謝你的迴應,我認爲這會奏效。我會看看我能做些什麼。 – Dbloom 2012-04-16 16:59:24
我最終創建了一個爲我保存所有AD屬性的類,然後創建了一個SortedList。這使我可以自動按日期排列列表中的元素,並且反轉順序非常簡單:'IEnumerable > revList = oldCompsList.Reverse();' –
Dbloom
2012-04-24 21:19:06