How to get SPUser object from SocialProfile in Sharepoint 2010?

2.5k Views Asked by At

How can I get the SPUser object associated to the profile from the SocialProfile in Sharepoint 2010?

Thanks

2

There are 2 best solutions below

0
On BEST ANSWER

Get the login name of the user as specified in the msdn article you linked. Then get the user for the given SPSite, since SharePoint users (and groups) are per site-collection:

SPWeb web = ...;
web.AllUsers["<loginName>"];

or if you want to create the user if it not already exits:

web.EnsureUser("<loginName>");
0
On

First, get the ID of the required user

UserProfile profile = GetProfile();
string userId = profile .MultiloginAccounts[0];

Second, get user from one of the following collections

web.AllUsers, web.Users or web.SiteUser

This article is about the differences http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/71d1c8e3-de32-4e3d-9f8c-7a9be13197f6/