Thursday, 6 September 2012

Get Colleagues of a User


Following is code to get the colleagues of the user:

using (SPSite site = new SPSite(url))
            {
                UserProfileManager userProfileManager = new UserProfileManager(SPServiceContext.GetContext(site));
                UserProfile userProfile = userProfileManager.GetUserProfile(accountName);
                UserProfile colleagueProfile = null;
                Colleague[] colleaguesOfCurrentUser = userProfile.Colleagues.GetItems();

                if (colleaguesOfCurrentUser != null)
                {
                    foreach (Colleague colleague in colleaguesOfCurrentUser)
                    {

                        colleagueProfile = colleague.Profile;
                       
                        //use the colleague profile to get the properties needed
                    }
                }
            }

No comments:

Post a Comment