用 DirectorySearcher 执行查询
mfood 2003-05-12 11:16:25 用 DirectorySearcher 执行查询
DirectoryEntry root = new DirectoryEntry("LDAP://redmond/CN=Users,DC=redmond,DC=corp,DC=microsoft,DC=com");
DirectorySearcher searcher=new DirectorySearcher(root);
searcher.Filter =“(&(objectClass=user)(lastName= Davis))”;
searcher.PropertiesToLoad.Add("cn");
searcher.PropertiesToLoad.Add("title");
searcher.PropertiesToLoad.Add("department");
SearchResultCollection results = searcher.FindAll();
foreach(SearchResult result in results)
{
string cn=result.Properties["cn"][0].tostring();
string title=result.Properties["title"][0].tostring();
string department=result.Properties["department"][0].tostring();
}
但是当result.Properties["x"][0].tostring()为空时。foreach语句自动结束一
轮循环。不会接着执行下一句.并会出错了.
提示:未实例化的.....