Dim netBIOSname As String = Me.Page.User.Identity.Name Dim sAMAccountName As String = netBIOSname.Substring(netBIOSname.LastIndexOf("\"c) + 1) txtuser.Text = sAMAccountName Try Dim userName As String = txtuser.Text Dim searcher As New DirectoryServices.DirectorySearcher( _ "(mailNickname=" + userName + ")") Dim result As DirectoryServices.SearchResult = searcher.FindOne() If result Is Nothing Then Label2.Text = "Unable to find user: " + userName Else Dim employee As DirectoryServices.DirectoryEntry = result.GetDirectoryEntry() txtfirstname.Text = employee.Properties("givenName").Value.ToString() txtlastname.Text = employee.Properties("sn").Value.ToString() txtfullname.Text = employee.Properties("cn").Value.ToString() txtempid.Text = employee.Properties("physicalDeliveryOfficeName").Value.ToString() txttitle.Text = employee.Properties("title").Value.ToString() txttele.Text = employee.Properties("telephoneNumber").Value.ToString() txtdept.Text = employee.Properties("department").Value.ToString() txtmobile.Text = employee.Properties("mobile").Value.ToString() Dim ManagerName As String = employee.Properties("manager").Value.ToString() ManagerName = ManagerName.Substring(3, ManagerName.IndexOf(",") - 3) Dim searchMgr As New DirectoryServices.DirectorySearcher("(cn=" + ManagerName + ")") Dim resultMgr As DirectoryServices.SearchResult = searchMgr.FindOne() If resultMgr Is Nothing Then Label2.Text = "Unable to find Manager: " + ManagerName Else Dim empManager As DirectoryServices.DirectoryEntry = resultMgr.GetDirectoryEntry() searchMgr.Dispose() resultMgr = Nothing empManager.Close() End If searcher.Dispose() result = Nothing employee.Close() End If Catch ex As Exception Label2.Text = "The following error occurred: " + ex.Message.ToString() End Try
retrieve user information from Active Directory
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)