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