0
我有一種方法,我正在使用獲取活動目錄中的部門列表。然而有些(至少有一個我知道)沒有出現。 「EMP-校友關係」是我目前正在排除故障的人。獲取活動目錄中的部門列表缺少某些部門
這是我使用的代碼。如果任何人可以識別任何潛在的問題,我將不勝感激。我目前處於虧損狀態。我已經確定了部門中的幾位用戶,所以我知道這不應該成爲問題。
ArrayList GetAdDepts ()
{
DirectoryEntry myLdapConnection = SCDirectoryEntry.GetDirectoryEntry ();
DirectorySearcher search = new DirectorySearcher (myLdapConnection);
search.Filter = "(objectClass=user)";
search.PropertiesToLoad.Add ("department");
SearchResultCollection result = search.FindAll ();
ArrayList departments = new ArrayList ();
foreach (SearchResult depart in result)
{
DirectoryEntry directoryEntry = depart.GetDirectoryEntry ();
if (directoryEntry.Properties.Contains ("department"))
{
string dept = (string) depart.Properties [ "department" ] [ 0 ];
if (dept.Trim ().StartsWith ("EMP-"))
{
if (!departments.Contains (dept))
{
departments.Add (dept);
}
}
}
}
return departments;
}
這做到了。非常感謝你,我欣賞代碼提示。 –