How can I extract the same employeeID attribute value that Outlook is displaying?

Viewed 3359

Our company uses ActiveDirectory for various reasons. One of them is to handle Outlook contacts and user log-in IDs.

I have written a program to detect the logged in user id, and to search the Active Directory using the extracted login id. The pulled information from the Active Directory is then stored in a database.

Here is the code I used to pull ActiveDirectory information data:

Dim enTry As DirectoryEntry = _
     New DirectoryEntry("LDAP://myCOMPANY/DC=myCOMPANY,DC=myCOMPANY,DC=com")

Dim mySearcher As DirectorySearcher = New DirectorySearcher(enTry)
mySearcher.Filter = "(&(objectClass=user)(anr=" & thisUser & "))" 
'thisUser is the variable holding the Windows ID that is accessing the ASPX page


mySearcher.PropertiesToLoad.Add("employeeID")   'just in case I need to do this.

Dim resEnt As SearchResult

Try
  For Each resEnt In mySearcher.FindAll()

  Dim fullname As String = resEnt.GetDirectoryEntry.Properties.Item("cn").Value
  'fullname will always pull the right information

  Dim e_id As String = resEnt.GetDirectoryEntry.Properties.Item("employeeID").Value
  'e_id will sometimes be NOTHING, sometimes will contain an ID that
  '   is different from the one displayed in Outlook Contact Information
  '   and sometimes it will be matching the employeeID listed in Outlook info

Catch ex as Exception
  Log("Failed to pull AD data: " & ex.Message)
End Try

For some reason, some users have no values for their employeeID field, and some have.

However, all of the users, will display an employeeID value when browsed in Outlook.

I designed the following image to help you understand what I am going through. The image is divided into two sections, a section for each CASE.

========================================================

In Case 1, the employee has logged in to Windows using his ID: xms33808

Outlook shows that his Employee ID is 16078

Outlook shows that his email alias is xms33808

ASP.Net command window shows that his employeeID is xms33808, which is not true

======================================================

=======================================================

In Case 2, the employee has logged in to Windows using ID: 25163

Outlook shows that his Employee ID is 25163

Outlook shows that his email alias is MutawaAAB

ASP.Net command windows shows that his employeeID is NOTHING.

=======================================================

My question is : How can I extract the same employeeID value information that Outlook is displaying?

Case 1: employeeID is different from ASP.Net than Outlook Case 2: employeeID is found in Outlook, but Nothing in ASP.Net

4 Answers
Related