Share via


設定搜尋篩選

搜尋篩選可根據物件的相關屬性 (例如,objectClass) 藉由搜尋物件來篩選特定物件。若要執行此動作,請設定篩選字串,字串中包含您期望的屬性。對於萬用字元搜尋,您可以輸入想要搜尋的字串的任何部分再加上 *,例如 (anr=test*)。在設定搜尋篩選搭配 System.DirectoryServices 使用時,請遵循 LDAP 篩選的語法規則。若要指定使用的篩選,請使用 DirectorySearcher 屬性 Filter

如需有關搜尋篩選的詳細資訊,請參閱 MSDN Library (https://go.microsoft.com/fwlink/?LinkID=27252 (本頁面可能為英文)) 中的<建立查詢篩選>主題。如需有關 objectClass 屬性的詳細資訊,請參閱 MSDN Library (https://go.microsoft.com/fwlink/?LinkID=27252 (本頁面可能為英文)) 中的<objectClass主題>。

下列程式碼範例示範如何加入搜尋篩選。

DirectoryEntry entry = new DirectoryEntry("LDAP://CN=users,DC=fabrikam,DC=com");
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = "(&(objectClass=user)(anr=test*))";
SearchResultCollection ResEnt = mySearcher.FindAll();
{
// Handle results.
}
// Handle exceptions.

請參閱

參考

System.DirectoryServices
DirectorySearcher

概念

搜尋目錄

Send comments about this topic to Microsoft.

Copyright © 2007 by Microsoft Corporation.All rights reserved.