Using the object model, I've retrieved the value from a people picker using standard method, and it returns a string value like this:


I have a problem with this because I was expecting the full username, including the domain. For example:


There must be a way to get the full user and domain name using the object model, but I don't know how.


I'm working with my PeopleEditor control this way:

foreach (var loginName in peopleEditor.CommaSeparatedAccounts.Split(';',','))
    SPUser user = SPContext.Current.Web.EnsureUser(loginName);
    // user.LoginName is now returns "domain\login"

This code works fine for me.


Note 1: EnsureUser will add the user to your site (thanks Ivan Padabed for the comment). In most cases it is ok, but better to remember this.

Note 2: This solution in most cases is most preferrable for me, than SPUtility.ResolvePrincipal. At least, because it is avaliable in Sandbox, and ResolvePrincipal isn't.

  • Can also use Name instead of loginName in order to get the login portion only. – trgraglia May 18 '11 at 8:12
  • Please note that way you all have side effect of adding picked user to the current web! – Ivan Padabed May 18 '11 at 10:22
  • @Ivan Padabed thanks for the comment! I've updated the answer. – Andrey Markeev May 18 '11 at 11:17
  • This is awesome. Works great. What if I wanted to get the display name as well? – SearchForKnowledge Mar 31 '15 at 14:25
  • user.Name should do the trick :) – Andrey Markeev Mar 31 '15 at 15:07

I believe you might also be able to use:

SPUtility.ResolvePrincipal(webApp, null, login, SPPrincipalType.User, SPPrincipalSource.All, false);

That said, this is slower than the suggestions using EnsureUser, but does have the benefit of not adding the user to the site, and is a bit more flexible, if you need that sort of thing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.