0

Is there any way I can get ONLY the first name of a user in WindowsIdentity? Now I'm getting full name by this code:

DirectoryEntry userEntry = new DirectoryEntry("WinNT://" + domain + "/" + userName + ",User");
string fullName = (string)userEntry.Properties["fullname"].Value;

But I want to seperate between first name and last name.

(right now I'm using split(' ') but there are users with two or more first and last name and I have no way to handel this.)

Thanks.

ParPar
  • 7,355
  • 7
  • 43
  • 56
  • Can you switch to the `LDAP:` provider rather than `WinNT:`? As you can see from the list of [unsupported IADsUser properties](http://msdn.microsoft.com/en-us/library/windows/desktop/aa746507(v=vs.85).aspx) the full user object has `FirstName` and `LastName` but they're not supported for the `WinNT` provider. – Damien_The_Unbeliever Jan 16 '14 at 11:22
  • How can I get the properties? You can't just replace `WinNT` with `LDAP` in the path, it gives nothing. Can you write an answer of how to use this? – ParPar Jan 16 '14 at 12:35

1 Answers1

0

As I assume that you want different properties for both: First name and last name. If so then you can use "FirstName" and "Surname" properties for the same.

string firstName = (string)userEntry.Properties["firstname"].Value;
string surname = (string)userEntry.Properties["surname"].Value;

Hope this helps.!!!

Maitrey684
  • 762
  • 5
  • 9