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 was using SPUtility.ResolvePrincipal to resolve the email address but it only seems to work if the user is already in the User Information List. Is there any way I can resolve users based on email if they do not yet exist in the User Information List?
I have 1,000 emails in the list that need to be resolved to people. There are about 60,000 users in the User Profile Service Application. How would you go about matching them?

Current code follows:

using (SPSite site = new SPSite("http://sp2010/sites/TheSite"))
{
   if (properties.ListItem["CONTACT EMAIL ADDRESS"] != null)
   {
       string email = properties.ListItem["CONTACT EMAIL ADDRESS"].ToString();
       SPWebApplication webApp = site.WebApplication;
       SPPrincipalInfo pi = null;
       pi = SPUtility.ResolvePrincipal(webApp, null, email, SPPrincipalType.User, SPPrincipalSource.Windows, true);
       if (pi != null)
       {
           UserProfile vmProfile = findUser(pi);
           if (vmProfile != null)
           {

               SPUser user = properties.Web.EnsureUser(pi.LoginName);
               SPFieldUserValue userName = new SPFieldUserValue(properties.Web, user.ID, user.Name);
               properties.ListItem["Vendor Manager"] = userName;
            }
        }
    }
}
share|improve this question

2 Answers 2

up vote 0 down vote accepted

I wrote an application that added users that are part of an AD group which contained all the users in the list. Then I deleted the group to remove the users that shouldn't have access. The code works if the users are in the user information list.

share|improve this answer

If the user is not in the User Information List, how would they have an associated SPUser object with a login etc.?

If ResolvePrincipal() didn't return null here, wouldn't this break when you tried to access a property like you do here: SPUser user = properties.Web.EnsureUser(pi.LoginName);

I think the short answer is no.

share|improve this answer
    
ResolvePrincipal returns null. I know I could at least compare the list of emails to profiles in the UPSA but that seems like a woefully inefficient way of doing it. –  James Grizzle Jul 31 '12 at 14:00
    
Yes, it does return null. By design. Sorry if you didn't catch the double negative in my above statement. If they don't exist in the User Information List, that's your only other option I guess, provided the user exists there and this isn't an external email address. –  RJ Cuthbertson Jul 31 '12 at 14:05

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.