Is it possible to get CustomProperties from a User Profile?

I would like to list all user profiles in a webpart including some custom properties which are imported from the AD by the User Profile Manager.

When I do this in code behind (SSOM) with the help of the UserProfileManager and access the web part as a farm admin all information including the custom properties is displayed. When I access the web part as a normal user the custom properties are not displayed.

When I try to use the PeopleManager in code behind I did not manage to find any way to query for custom properties.

EDIT (2013/11/25):

Even though the permissions are set up like Falak suggested it is not working. Therefore it will add the snippet of code here. So maybe can check this on their side to see whether it is working.

    SPSite site = SPContext.Current.Site;
    SPServiceContext serviceContext = SPServiceContext.GetContext(site);
    UserProfileManager upm = new UserProfileManager(serviceContext);
    IEnumerator userProfiles = upm.GetEnumerator();
    using (new SPMonitoredScope("loading User Profiles"))
        while (userProfiles.MoveNext())
            UserProfile userProfile = (UserProfile)userProfiles.Current;
            if (userProfile.GetProfileValueCollection("l").Value != null)
                string location = userProfile.GetProfileValueCollection("l").Value.ToString();
                //display location in web part

When a "normal" user accesses the web part the location is not displayed. When I access the web part with the farm admin account everything is working as expected as mentioned before. "l" is the custom property which is synced from the AD by the User Profile Manager.

  • Which metod in the PeopleManager are you using? Nov 22, 2013 at 10:17
  • I'm guessing PeopleManager.getPropertiesFor("accountname).UserProfileProperties? Nov 22, 2013 at 10:19
  • @Robert Yes, I'm trying to use this one or using the method to query one specific property e.g. PeopleManager.GetUserProfilePropertyFor("accountName", "Entrydate")
    – André
    Nov 22, 2013 at 10:23
  • 1
    Have you tried the full code example here: msdn.microsoft.com/en-us/library/jj163182.aspx to see if the property exists in the collection? Nov 22, 2013 at 11:15
  • Yes I did @Robert. Unfortunately all custom properties do not exist in this collection.
    – André
    Nov 22, 2013 at 11:40

2 Answers 2


You need to set the correct permissions in User profiles service application!

  1. Go to Central Admin
  2. Manage Service Applications -> User Profile Service Application
  3. Click Administrators in the ribbon and add the user and set the Manage Profiles permission for it

If you're running your code as ElevatedPrivileges then I assume the identity of the application pool - this account is configured as an Administrator of User Profile Service Application?

  • Even though I'm running the code with ElevatedPrivileges it makes a difference which user accesses the web part. This confuses me a lot. I will test your approach tomorrow when I'm back at work.
    – André
    Nov 24, 2013 at 21:42
  • With ElevatedPrivileges your code will be executed under application pool account (with full permissions) or in other words permissions for users will not be taken into the account. Though, you must ensure the permissions for application pool over user profile service. Nov 24, 2013 at 22:21
  • Even though the permissions are set up like you described this is not working on my side. I will add the code snippet to the original question so that you can see what I'm trying to do.
    – André
    Nov 25, 2013 at 7:51

Make sure the properties are configured to be publicly retrievable.

To do this, edit the User Profile property and make sure that "Default Privacy Setting" is set to "Everyone".

  • It is already set to this value.
    – André
    Nov 22, 2013 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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