none
get users manager name client object model RRS feed

  • Question

  • Hello all,

    Is is possible to get the Supervisor/manager's name of an user through client object model.I tried SiteUserInfoList list ,but no use

    any suggestions?

    Thanks


    Like Cricket

    Tuesday, September 18, 2012 8:16 PM

Answers

  • Hello,

    For SharePoint 2010 I think you need to use something like this 

     using (SPSite site = new SPSite("Site URL"))
                {
                    SPServiceContext context = SPServiceContext.GetContext(site);
                    UserProfileManager upm = new UserProfileManager(context);
                    UserProfile profile = upm.GetUserProfile("Domain\\UserName");
                    UserProfile profileManager = profile.GetManager();
                }


    with those dll

    using Microsoft.SharePoint;
    using Microsoft.Office.Server.UserProfiles;



    Best regards, Christopher.
    Blog | Mail
    Please remember to click "Mark As Answer" if a post solves your problem or "Vote As Helpful" if it was useful.
    Why mark as answer?


    Tuesday, October 2, 2012 6:37 AM
    Answerer

All replies

  • You can get the manager of a user profile by calling the user profile service application web service. Take a look at this class which is available through the web service.

    http://msdn.microsoft.com/en-us/library/websvcuserprofileservice.incommondata.aspx


    SharePoint Developer | @zeemanj | Blog

    Tuesday, September 18, 2012 10:14 PM
  • Hi,

    Please try belo code

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.SharePoint.Client;
    using Microsoft.SharePoint.Client.UserProfiles;
    
    namespace UserProfilesCSOM
    {
        class Program
        {
            static void Main(string[] args)
            {
    
                // Replace the following placeholder values with the target SharePoint site and
                // target user.
                const string serverUrl = "http://serverName/";  
                const string targetUser = "domainName\\userName";  
    
                // Connect to the client context.
                ClientContext clientContext = new ClientContext(serverUrl);
    
                // Get the PeopleManager object and then get the target user's properties.
                PeopleManager peopleManager = new PeopleManager(clientContext);
                PersonProperties personProperties = peopleManager.GetPropertiesFor(targetUser);
    
                // Load the request and run it on the server.
                // This example requests only the AccountName and UserProfileProperties
                // properties of the personProperties object.
                clientContext.Load(personProperties, p => p.AccountName, p => p.UserProfileProperties);
                clientContext.ExecuteQuery();
    
                foreach (var property in personProperties.UserProfileProperties)
                {
                    Console.WriteLine(string.Format("{0}: {1}", 
                        property.Key.ToString(), property.Value.ToString()));
                }
                Console.ReadKey(false);
    
                // TODO: Add error handling and input validation.
            }
        }
    }
    

    And check for all the properties returned, if manager name is sync with UPS then you should get it.

    Also have a look at this MSDN thread, might help you.

    http://social.technet.microsoft.com/Forums/en-GB/sharepoint2010programming/thread/6ce46461-24f3-4a40-95ae-fd33bd1747e4


    Thanks.... ________________ Baba (MCTS, MCPD)

    Wednesday, September 19, 2012 5:02 AM
  • Thanks for the reply Mr.Baba. what is the path for Microsoft.SharePoint.Client.UserProfiles.dll I did check but I didnt get it in ISAPI folder

    Like Cricket



    Wednesday, September 19, 2012 7:31 AM
  • The DLL should be available in C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI. Are you using SharePoint Foundation?

    SharePoint Developer | @zeemanj | Blog

    Thursday, September 20, 2012 7:20 PM
  • Thank you Jeffrey,but its 2013 ,its sharepoint 2010 only

    Like Cricket

    Friday, September 21, 2012 2:32 AM
  • Hello,

    For SharePoint 2010 I think you need to use something like this 

     using (SPSite site = new SPSite("Site URL"))
                {
                    SPServiceContext context = SPServiceContext.GetContext(site);
                    UserProfileManager upm = new UserProfileManager(context);
                    UserProfile profile = upm.GetUserProfile("Domain\\UserName");
                    UserProfile profileManager = profile.GetManager();
                }


    with those dll

    using Microsoft.SharePoint;
    using Microsoft.Office.Server.UserProfiles;



    Best regards, Christopher.
    Blog | Mail
    Please remember to click "Mark As Answer" if a post solves your problem or "Vote As Helpful" if it was useful.
    Why mark as answer?


    Tuesday, October 2, 2012 6:37 AM
    Answerer