5
我目前这个代码,的Active Directory目录OU的
string defaultNamingContext;
DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE");
defaultNamingContext = rootDSE.Properties["defaultNamingContext"].Value.ToString();
rootDSE = new DirectoryEntry("LDAP://" + defaultNamingContext);
//DirectoryEntry domain = new DirectoryEntry((string)"LDAP://" + defaultNamingContext);
DirectorySearcher ouSearch = new DirectorySearcher(rootDSE,"(objectCategory=Organizational-Unit)",
null, SearchScope.Subtree);
MessageBox.Show(rootDSE.Path.ToString());
try
{
SearchResultCollection collectedResult = ouSearch.FindAll();
foreach (SearchResult temp in collectedResult)
{
comboBox1.Items.Add(temp.Properties["name"][0]);
DirectoryEntry ou = temp.GetDirectoryEntry();
}
}
当我使用调试器,我可以看到,rootDSE.Path是逸岸指向正确的地方,在这种情况下DC=g-t-p,DC=Local
但目录搜索没有按”找到任何结果。谁能帮忙?
OMG这么简单的东西,踢自己不付出努力,经过我的几几小时的试用和错误编码:@ 我不认为它是我最近的最高产... – 2010-05-25 16:22:45
它看起来像我正在收集搜索对象正确地将它们添加到组合框项目? – 2010-05-25 16:23:30
+1自己测试了一下,然后写出我的答案,我得出了同样的结论。 – 2010-05-25 16:25:22