I've developed WCF service to get all user profile information from SharePoint 2010 where there's a lot of custom properties including taxonomy fields. When I run the below code, it's only return current login user profile information. After I added Impersonation code [SPSecurity.RunWithElevatedPrivileges], it returns all of the user informations. But I need AppPool Account to give "Manage User Profiles" permission in User Profile Service Application. Is there any other work around without impersonation? Is it causing because of using (parmUserProfile.Properties.GetPropertyByName and ProfileSubtypeProperty.TypeProperty.CoreProperty.IsMultivalued? It would be highly appreciated any of your inputs. Thank in advance.
siteUrl = WebConfigHelper.GetMyPageSiteUrl();
using (SPSite userprofilesite = new SPSite(siteUrl))
{
SPServiceContext serviceContext = SPServiceContext.GetContext(userprofilesite);
// Initialize user profile config manager object
UserProfileManager userProfileManager = new UserProfileManager(serviceContext);
foreach (Microsoft.Office.Server.UserProfiles.UserProfile profile in userProfileManager)
{
peopleProfile.AccountName = GetMultiValue(profile, colAccountName, showMsg).ToString();
peopleProfile.AskMeAbout = GetMultiValue(profile, colAskMeAbout, showMsg); //Multivalued column
}
{
List<string> retValue = new List<string>();
string msgMissingProperty = "Missing Property - ";
try
{
if (parmUserProfile.Properties.GetPropertyByName(parmPropertyName) != null)
{
if ((parmUserProfile[parmPropertyName].Value != null) && (!string.IsNullOrEmpty(parmUserProfile[parmPropertyName].Value.ToString())))
{
if (parmUserProfile[parmPropertyName].ProfileSubtypeProperty.TypeProperty.CoreProperty.IsMultivalued)
{
UserProfileValueCollection propertyCollection = parmUserProfile[parmPropertyName];
foreach (var item in propertyCollection)
{
retValue.Add(item.ToString());
}
}
else
retValue.Add(parmUserProfile[parmPropertyName].Value.ToString());
}
}
else
if (showCustomMsg)
retValue.Add(msgMissingProperty + parmPropertyName);
}
catch (Exception ex)
{
}
return retValue;
}
*Understand that Properties.GetPropertyByName is obsolete.