While working with SharePoint user profile through code, I got an error when accessing the user profile from user profile manager. Stack trace has thrown the error as,
Microsoft.Office.Server.UserProfiles.UserNotFoundException was unhandled
Message=An error was encountered while retrieving the user profile.
Source=Microsoft.Office.Server.UserProfiles
I have checked in User profile service that account crawled correctly or not. Yes it is there. Iam able to get the user in SharePoint user picker as expected. I have googled about the issue for some time. I have fixed the exception using an article from technet. Tip shown in the blog post fixed my error.
Actually iam getting the error from following code line
UserProfile currentUser = profileManager.GetUserProfile("Domain\UserName")
Microsoft.Office.Server.UserProfiles.UserNotFoundException was unhandled
Message=An error was encountered while retrieving the user profile.
Source=Microsoft.Office.Server.UserProfiles
I have checked in User profile service that account crawled correctly or not. Yes it is there. Iam able to get the user in SharePoint user picker as expected. I have googled about the issue for some time. I have fixed the exception using an article from technet. Tip shown in the blog post fixed my error.
Actually iam getting the error from following code line
UserProfile currentUser = profileManager.GetUserProfile("Domain\UserName")
Here profilemanager is UserProfileManager object. After changing “\” to “\\” in user profile my issue got fixed. I have replaced my code line with
UserProfile currentUser = profileManager.GetUserProfile("Domain\\UserName")
Simple. Hope this will help you.
UserProfile currentUser = profileManager.GetUserProfile("Domain\\UserName")
Simple. Hope this will help you.