Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am looping through a group of UserPrincipal that was retrieved from Active Directory. I need to get find a SPUser using the properties of the UserPrincipal. Once the SPUser is found I will get its UserProfile["PreferredName"].

I have tried passing all of the following to SPUser and the exception says user not found:

  1. UserPrincipal.UserPrincipalName
  2. UserPrincipal.DisplayName

I should also mention the reason I need to find the Preferred Name is because the UserPrincipal.DisplayName that I will eventually pass to a People Picker is resolving as the Preferred Name which I am afraid will mess us up later. I have already synced the Preferred Names, there are just a couple that are stuck as 'domain/username' instead of 'firstname lastname'.

Any ideas?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

AD users don't exist on SharePoint until something causes SharePoint to know about them (e.g. an explicit permission setting, the user has logged in, etc).

Try using SPWeb.EnsureUser(string userlogonname) - it will create the user within SharePoint if it doesn't already exist, and return the SPUser object.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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