I am trying to get user profile image from user profile. Here is my code sample:
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
{
SPServiceContext ctx = SPServiceContext.GetContext(site);
UserProfileManager upm = new UserProfileManager(ctx); // Here I get error
if (upm.UserExists(loginUserName))
{
UserProfile up = upm.GetUserProfile(loginUserName);
if (!string.IsNullOrWhiteSpace(Convert.ToString(up["PictureUrl"].Value)))
{
this.userimage = Convert.ToString(up["PictureUrl"].Value);
}
}
}
});
But I get below error if user profile doesn't exist at userProfileManager
declaration in above code:
An exception of type 'Microsoft.Office.Server.UserProfiles.UserProfileApplicationNotAvailableException' occurred in Microsoft.Office.Server.UserProfiles.dll but was not handled in user code
Additional information: UserProfileApplicationNotAvailableException_Logging :: UserProfileApplicationProxy.GetRawPartitionID has null proxy
Is there any other way through which I can check if user profile exist programmatically? Thanks in advance.