Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
    
What if you moved all but the last two "UserProfile" lines out of the delegate? –  John Chapman Dec 3 '12 at 19:17
    
The same thing happens if I move all but the last two "UserProfile" lines out of the delegate. –  Jeremy Dec 3 '12 at 19:22
add comment

1 Answer

up vote 2 down vote accepted

The empty Guid here actually is not concerning. The SiteSubscriptionId will always be a blank Guid unless you have multi-tenancy enabled in your environment.

Enabling Multi Tenant Support in SharePoint 2010

You may need to add permission for your user on the User Profile Service Application.

In Configure User Profile sync connections they were trying to get the UserProfileManager via PowerShell and getting an error (NullReferenceException) but resolved it by ensuring the user account attempting to get the UserProfileManager had permissions:

1) As a administrator with full control

2) connection permissions as full control

Then you have access to the connection manager and can programatically access the connections.

share|improve this answer
    
I am still getting a SPServiceContext with a SiteSubcriptionId of {00000000-0000-0000-0000-000000000000}, causing a null UserProfileManager. I tried moving the first three lines out of the delegate, and the same thing happens. –  Jeremy Dec 3 '12 at 19:14
    
Just saw your link. I am checking that out now... –  Jeremy Dec 3 '12 at 19:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.