Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11508

Why return only one user profile from SharePoint 2010 when I'm trying to get all users

$
0
0

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

}

        private List<string> GetMultiValue(UserProfile parmUserProfile, string parmPropertyName, bool showCustomMsg)
        {
            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.


Viewing all articles
Browse latest Browse all 11508

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>