我有一个方法,我正在使用获取我们活动目录中的部门列表。但是有些(至少我知道的)没有出现。“EMP-Alumni Relations”是我目前正在解决的问题。
这是我正在使用的代码。如果有人能找出任何潜在的问题,我将不胜感激。我一时不知所措。我已经确定了部门中的几个用户,所以我知道这不应该是问题。
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;
}