Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do I get the current users full name from active directory

Posted on 2009-04-20
8
Medium Priority
?
598 Views
Last Modified: 2013-11-26
I have a text field and I want the text field to be populated with the current users full name from the active directory.
I've found code on getting the user name from active directory but I want the full name of the user.
Example: username might be CUNNINDV
but the user's full name is David Cunningham
David Cunningham is what I want to display.
Any help is appreciated!!!!!
0
Comment
Question by:mmtcunningham1
  • 4
  • 3
8 Comments
 
LVL 11

Expert Comment

by:jmwheeler
ID: 24186403
Try this:

DirectoryEntry userEntry = new DirectoryEntry("WinNT://" + userName +",User");      
retVal = (string)userEntry.Properties["fullname"].Value;
0
 
LVL 11

Assisted Solution

by:jmwheeler
jmwheeler earned 1600 total points
ID: 24186596
My example above should be more clear.   You need to have your domain after winnt and then a slash and then the username.

DirectoryEntry userEntry = new DirectoryEntry("WinNT://YOURDOMAIN/USERNAME",User");      
retVal = (string)userEntry.Properties["fullname"].Value;
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:mmtcunningham1
ID: 24187341
jmwheeler:
directoryEntry not defined.  am I missing something????
0
 
LVL 11

Expert Comment

by:jmwheeler
ID: 24187402
My refined example had an additional double-quote that wasn't needed.

You need to add a reference to System.DirectoryServices to your project/website.  Also, I think you might be using VB so the code needs converted from C#, I'm not a VB user but here is my best guess.

Dim userEntry as DirectoryEntry = new DirectoryEntry("WinNT://YOURDOMAIN/USERNAME, User")
Dim retVal as string = userEntry.Properties("fullname").Value.ToString()
0
 
LVL 11

Expert Comment

by:jmwheeler
ID: 24187415
You also need to specify that your code should use the System.DirectoryServices namespace.  I'm not sure if VB has a "using" statement but you can always just include it right in the code.

Dim userEntry as System.DirectoryServices.DirectoryEntry = new System.DirectoryServices.DirectoryEntry("WinNT://YOURDOMAIN/USERNAME, User")

Open in new window

0
 

Accepted Solution

by:
mmtcunningham1 earned 0 total points
ID: 24196686
I got it to work!!!
Here's the code to do it:

Dim DomainUser As String = System.Security.Principal.WindowsIdentity.GetCurrent.Name.Replace("\", "/")
Dim ADEntry As New System.DirectoryServices.DirectoryEntry("WinNT://" & DomainUser)
Dim FullName As String = ADEntry.Properties("FullName").Value
0
 

Author Comment

by:mmtcunningham1
ID: 24196735
n/a
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question