LDAP or active directory?

M

Mike

In my current asp.net application i'm getting the user network short name
and displaying that on the screen. What I want is the users Full name and
display that instear. How can i go about doing that, would I use LDAP or
Active directory to do that?

I never had to do this and not sure how to do it or where to start looking.

Ex: this is what i get now.
jsmith - network logon ID

what I want is:
John Smith.

is this possible?
thx
 
E

Eric Guillemette

This function do exactly what you need :0)

I'm using this function with WinForms, but I think that's will work in
Asp.Net too.

Public Shared Function GetFullName(ByVal DomainName As String, ByVal
UserName As String) As String
Dim oDirectory As New DirectoryEntry("LDAP://" & DomainName)
Dim mySearcher As New DirectorySearcher(oDirectory)
Dim oResult As SearchResult
Dim sResult As String
mySearcher.SearchScope = SearchScope.Subtree
mySearcher.ReferralChasing = ReferralChasingOption.All
mySearcher.Filter = "(&(objectClass=user)(sAMAccountName=" & UserName &
"))"

Try
oResult = mySearcher.FindOne
If Not oResult Is Nothing Then
sResult =
oResult.GetDirectoryEntry.Properties("DisplayName").Value.ToString
End If
Catch ex As Exception
Throw ex
End Try

oResult = Nothing
mySearcher.Dispose()
oDirectory.Dispose()

Return sResult
End Function
 
E

Eric Guillemette

You can do anything you want, this function return a string wich contains
the full name of the user.

Exemple:

'My domain name's: MyDomain
'My UserName's: Eric
Dim s As String = GetFullName("MyDomain", "Eric")

The variable 's' will contain "Eric Guillemette" (My full name)

you can put this in a label, combobox, whatever...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top