Answered by:
An error was encountered while retrieving the user profile (sharpoint 2010 development) - Microsoft.Office.Server.UserProfiles.UserNotFoundException

Question
-
Hi,
To retrieve UserProfile I am using following code for sharepoint 2010 using vs 2010:
private UserInfo GetUserInfo() { UserInfo userInfo = new UserInfo(); SPServiceContext ctx = SPServiceContext.Current; //ServerContext.GetContext("SharedServices1"); UserProfileManager profileManager = new UserProfileManager(ctx); UserProfile profile = profileManager.GetUserProfile(@"" + SPContext.Current.Web.CurrentUser.LoginName); if (profile["WorkEmail"] != null && !string.IsNullOrEmpty(profile["WorkEmail"].ToString())) userInfo.EmailAddress = profile["WorkEmail"].ToString(); }
I am getting following error at line -->
UserProfile profile = profileManager.GetUserProfile(@"" + SPContext.Current.Web.CurrentUser.LoginName);
ERROR: Microsoft.Office.Server.UserProfiles.UserNotFoundException: An error was encountered while retrieving the user profile.
I am able to see the userPofile against my Active Directory connection I made. Also I am able to manage User profile from Central Admninistration -> Manage Service Applications -> User Profile Service Application -> Manage User Profiles (when i type an Active Directory user and Click Find it returns me that user profile and I am able to update from there with same credentials when used by code it returns me the above error.)
Please let me know how to get User Profile using code above ?
Shamshad Ali.
Monday, July 26, 2010 11:28 AM
Answers
-
Fixed this by replacing the change in Error Line as:
UserProfile profile = profileManager.GetUserProfile(SPContext.Current.Web.CurrentUser.RawSid);
This worked without any problem....
Shamshad Ali
- Marked as answer by Shamshad Ali Monday, July 26, 2010 1:00 PM
Monday, July 26, 2010 1:00 PM
All replies
-
Fixed this by replacing the change in Error Line as:
UserProfile profile = profileManager.GetUserProfile(SPContext.Current.Web.CurrentUser.RawSid);
This worked without any problem....
Shamshad Ali
- Marked as answer by Shamshad Ali Monday, July 26, 2010 1:00 PM
Monday, July 26, 2010 1:00 PM -
hi Shamshad,
Your solution didn't work for me... Any other way to make it work?
thanks
Monday, July 4, 2011 8:21 PM -
HI,
I got the same problem...how did u resolved this issue?
I am doing like this:
SPSite site = SPContext.Current.Site; SPServiceContext svcContext = SPServiceContext.GetContext(site); UserProfileManager uspManager = new UserProfileManager(svcContext); string accountName = domainName +"\\"+fname + "." + lname; UserProfile userProfile = uspManager.GetUserProfile(accountName);
Thanks,PVSAVSG.
- Edited by pvsavsg Wednesday, March 7, 2012 11:13 AM modified code
Wednesday, March 7, 2012 11:11 AM -
hi,
How do u do it if its in mysites and the details of the user to get is not of who logged in but the ones who we are seeing?Friday, March 9, 2012 12:09 PM