Hi,
I need some help with my Active Directory coding in C#. All I am trying to do is quey the active directory on my server to return information about a user such as first name, surname etc. Here is my code at the moment:
With this code the program stops at the directoryObject line saying:
Object reference not set to an instance of an object
Any ideas please?
Many thanks in advance.
I need some help with my Active Directory coding in C#. All I am trying to do is quey the active directory on my server to return information about a user such as first name, surname etc. Here is my code at the moment:
Code:
DirectoryEntry de = new DirectoryEntry("LDAP://ServersIPAddress");
DirectorySearcher srch = new DirectorySearcher(de);
srch.Filter = "(&(objectClass=user)(|(cn=PersonsUsername)))";
SearchResult result = srch.FindOne();
DirectoryEntry directoryObject = new DirectoryEntry();
directoryObject = result.GetDirectoryEntry();
Object reference not set to an instance of an object
Any ideas please?
Many thanks in advance.