Getting the Login Name for a Given Display Name in SharePoint

Yes, It’s possible to retrieve the LoginName of a user if you only have the DisplayName ( Last Name + First Name ).

There are a lot of ways to achieve that like :

  1. You can directly query the Active Directory.
  2. You can use a PeopleEditor control, which will grab the user if you type in the lastname, firstname combination as follows :
    PeopleEditor people = new PeopleEditor(); people.MultiSelect = false;
    int userID = Int32.Parse((((PickerEntity)people.ResolvedEntities[0]).EntityData[“SPUserID”]).ToString());
    SPUser user = SPContext.Current.Site.RootWeb.SiteUsers.GetByID(userID);
  3. You can use SharePoint Search API ( FullTextSqlQuery Class ) :
    SELECT AccountNameFROM portal..scope()WHERE ( (“SCOPE” = ‘People’) ) AND (“Title” = ‘[DISPLAY NAME]’)

I prefer the third way, much easier.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s