I am trying to get a user's manager with this code:
SPSecurity.RunWithElevatedPriviliges(delegate
{
SPSite site = new SPSite(SPContext.Current.Site.Url);
SPServiceContext context = SPServiceContext.GetContext(site);
UserProfileManager profileManager = new UserProfileManager(context);
//Note that I have an SPUser object, user, previously defined.
UserProfile userProfile = profileManager.GetUserProfile(user.ID);
UserProfile managerProfile = userProfile.GetManager();
});
My problem is that I am getting a null UserProfileManager. I suspect it's because the SPServiceContext has a SiteSubcriptionId of {00000000-0000-0000-0000-000000000000}.
I am debugging this on my local SharePoint server. I am running it on a development environment on Windows 7. Does this error indicate a problem with my environment?
Is there a better way to get the manager of a given SPUser?
EDIT:
It appears neither my local machine or my test server has the User Profile Service set up properly. So that is probably why it's not working. I'm going to attempt to get that working and see if I still have the problem.