A UserPrincipal
is a part of the System.DirectoryServices.AccountManagement
namespace.
Use the helper classes in that namespace to get UserPrincipal
objects.
Without using a UserPrincipal
try something like this:
using (var userBinding = new DirectoryEntry("LDAP://domain.forest.company.com"))
{
using (DirectorySearcher adSearch = new DirectorySearcher(userBinding))
{
adSearch.ReferralChasing = ReferralChasingOption.All;
adSearch.Filter = "(&((&(objectCategory=Person)(objectClass=User)))(samaccountname=" + username + "*))";
adSearch.PropertiesToLoad.Add("employeeID");
adSearch.PropertiesToLoad.Add("givenname");
adSearch.PropertiesToLoad.Add("samaccountname");
var result = adSearch.FindOne();
var employeeId = result.Properties["employeeID"][0].ToString();
}
}