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.
SPSecurity.RunWithElevatedPrivileges(delegate()
{
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.