Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

we can get directly user information by using Server object but how to get this by using Client object model ?

share|improve this question
    
Are you looking to use Client side/JSOM? –  Stephen Jan 28 at 11:04
    
Client Side code –  Rajesh Joshi Jan 28 at 11:38

1 Answer 1

How to work with user profiles via CSOM in SharePoint 2010

It is not supported to access User Profiles via CSOM in SharePoint 2010, but it is possible to archive via UserProfileService SOAP service

Example (SPServices is used here):

$().SPServices({
    operation: "GetUserProfileByName", 
    AccountName: login, // put login name here
    completefunc:function(data,status) {
        var profile = {};
        $(data.responseText).find("PropertyData").each(function(idx, val) {
            var $val = $(val);
            var name = $val.find("Name").text();
            var value = $val.find("Value").text();
            profile[name] = value;
        });

        // At this point the profile object has all profile properties:
        console.log(profile.PreferredName);
        console.log(profile.WorkEmail);
        console.log(profile['SPS-StatusNotes']);
    }
});

The list of operations for UserProfileService service could be found here


How to work with user profiles via CSOM in SharePoint 2013

Example: how to retrieve a specific set of user profile properties for a target user:

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 the
            // 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.
            PeopleManager peopleManager = new PeopleManager(clientContext);

            // Retrieve specific properties by using the GetUserProfilePropertiesFor method. 
            // The returned collection contains only property values.
            string[] profilePropertyNames = new string[] { "PreferredName", "Department", "Title" };
            UserProfilePropertiesForUser profilePropertiesForUser = new UserProfilePropertiesForUser(
                clientContext, targetUser, profilePropertyNames);
            IEnumerable<string> profilePropertyValues = peopleManager.GetUserProfilePropertiesFor(profilePropertiesForUser);

            // Load the request and run it on the server.
            clientContext.Load(profilePropertiesForUser);
            clientContext.ExecuteQuery();

            // Iterate through the property values.
            foreach (var value in profilePropertyValues)
            {
                Console.Write(value + "\n");
            }
            Console.ReadKey(false);

            // TO DO: Add error handling and input validation.
        }
    }
}

Source

References

Work with user profiles in SharePoint 2013

share|improve this answer
    
This code is for SP2013 but i want for SP2010 –  Rajesh Joshi Jan 28 at 11:34
2  
@RajeshJoshi, a tip is to make that clear in your post, I see that Vadmin had to do it for you. –  Robert Lindgren Jan 28 at 11:51
    
Microsoft.SharePoint.Client.UserProfiles is not available in Sp2010 –  Rajesh Joshi Jan 28 at 11:55
    
The answer has been updated –  Vadim Gremyachev Jan 28 at 12:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.