• This email address is being protected from spambots. You need JavaScript enabled to view it.

    Recent items


Tuesday, 12 February 2013 21:00

Retrieve User profile properties via SharePoint Client Object Model

Written by
Rate this item
(0 votes)

In this example, I wanto to explain how to use the Client Object Model to retrieve User Profile Properties.

In my example, I have a list with some fields and one of this is a SPFieldUserValue (UserField is the internal name of my field).

Show/Hidden csharp code

View source
ClientContext clientContext = new ClientContext("htttp://");
clientContext.Credentials = new System.Net.NetworkCredential("username", "password", "domain");
Site siteCol = clientContext.Site;
Microsoft.SharePoint.Client.Web web = clientContext.Web;
clientContext.Load(web, w => w.Title, w => w.Language, w => w.ServerRelativeUrl);
clientContext.Load(web, c => c.Lists);
List list = web.Lists.GetByTitle("CustomList");
var userInfoList = clientContext.Web.SiteUserInfoList;
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View/>";
Microsoft.SharePoint.Client.ListItemCollection items = list.GetItems(camlQuery);
foreach (Microsoft.SharePoint.Client.ListItem item in items)
    var temp = item["UserField"];
    var query = new CamlQuery { ViewXml = "<View Scope='RecursiveAll'><Query><Where><Eq><FieldRef Name='ID' /><Value Type='int'>" + ((FieldUserValue)temp).LookupId + "</Value></Eq></Where></Query></View>" };
    var user = userInfoList.GetItems(query);
    if (user.Count > 0)
        //here I retrieve only Name property. You can iterate on all properties to view all User properties
        string name = user[0].FieldValues["Name"] as string;
        Console.WriteLine(string.Format("User found {0} with id {1}", name.Split('|').LastOrDefault(), user[0].Id));
        Console.WriteLine(string.Format("User not found: {0} with id {1}", ((FieldUserValue)temp).LookupValue;, ((FieldUserValue)temp).LookupId.ToString()));

Read 14119 times Last modified on Tuesday, 12 January 2016 10:41

1 comment

  • Comment Link Annie Saturday, 24 September 2016 03:10 posted by Annie

    Thanks for sharing your info. I really appreciate your efforts and I am waiting for
    your further post thanks once again.


Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.