Hi, I'm using the function below to retrieve the full name of the logged on person, by retrieving the Display Name from Active Directory
Protected Function GetLogonUserFullName() As String
Dim strFullName As String = String.Empty
Dim wi As System.Security.Principal.WindowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent()
Dim a As String() = Context.User.Identity.Name.Split("\"c)
Dim userName As String = Me.Context.User.Identity.Name
Dim domain As String = "Domain Name"
Dim properties As String() = New String() {"displayname"}
Dim adRoot As New DirectoryEntry("LDAP://" & domain, Nothing, Nothing, AuthenticationTypes.Secure)
' Create a DirectorySearcher object using the user name ' as the LDAP search filter. If using a directory other
' than Exchange, use sAMAccountName.
Dim searcher As DirectorySearcher = New DirectorySearcher("(sAMAccountName=" + a(1) + ")")
'' Search for the specified user.
Dim Result As SearchResult = searcher.FindOne()
' Make sure the user was found.
If Result Is Nothing Then
strFullName = "User not found " + userName
Else
' Create a DirectoryEntry object to retrieve the collection' of attributes (properties) for the user.
Dim employee As DirectoryEntry = Result.GetDirectoryEntry()
' Assign the specified properties to string variables.
Dim UserFullName As String = employee.Properties("displayname").Value.ToString
strFullName = UserFullName
'clean up
searcher.Dispose()
Result = Nothing
employee.Close()
End If
Return strFullName
End Function
Is there a way I could get the initials of the user instead, or the description?
danieldunn10
Member
389 Points
383 Posts
Active Directory Information
Feb 29, 2012 11:50 AM|LINK
Hi, I'm using the function below to retrieve the full name of the logged on person, by retrieving the Display Name from Active Directory
Protected Function GetLogonUserFullName() As String Dim strFullName As String = String.Empty Dim wi As System.Security.Principal.WindowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent() Dim a As String() = Context.User.Identity.Name.Split("\"c) Dim userName As String = Me.Context.User.Identity.Name Dim domain As String = "Domain Name" Dim properties As String() = New String() {"displayname"} Dim adRoot As New DirectoryEntry("LDAP://" & domain, Nothing, Nothing, AuthenticationTypes.Secure) ' Create a DirectorySearcher object using the user name ' as the LDAP search filter. If using a directory other ' than Exchange, use sAMAccountName. Dim searcher As DirectorySearcher = New DirectorySearcher("(sAMAccountName=" + a(1) + ")") '' Search for the specified user. Dim Result As SearchResult = searcher.FindOne() ' Make sure the user was found. If Result Is Nothing Then strFullName = "User not found " + userName Else ' Create a DirectoryEntry object to retrieve the collection' of attributes (properties) for the user. Dim employee As DirectoryEntry = Result.GetDirectoryEntry() ' Assign the specified properties to string variables. Dim UserFullName As String = employee.Properties("displayname").Value.ToString strFullName = UserFullName 'clean up searcher.Dispose() Result = Nothing employee.Close() End If Return strFullName End FunctionIs there a way I could get the initials of the user instead, or the description?
Thanks very much
saalameejen
Member
210 Points
50 Posts
Re: Active Directory Information
Feb 29, 2012 12:33 PM|LINK
check this, this will help you
http://www.rshelby.com/post/active-directory-user-object.aspx
http://www.rlmueller.net/Name_Attributes.htm
nbsamurai
Member
592 Points
220 Posts
Re: Active Directory Information
Feb 29, 2012 12:35 PM|LINK
Hi,
Try the below links
http://www.codeproject.com/Articles/6778/How-to-get-User-Data-from-the-Active-Directory
http://www.aspdotnet-suresh.com/2011/03/how-to-get-userdetails-from-active.html