Since SharePoint 2010, Microsoft announced Client object model to developer community and it really help to extent SharePoint to many other platform.  SharePoint client object model (CSOM) allow you to manage data in SharePoint such as list data, user profile, ….

In SharePoint 2013, I’m very impressive with CSOM since it support for multiple plat for

  • .NET Framework redistributable assemblies
  • JavaScript library
  • REST/OData endpoints
  • Windows Phone assemblies
  • Silverlight redistributable assemblies

This artile show a code snippet for demo how to get user from a list data

        public static User GetUserFromAssignedToField() 
        { 
            string strUrl="http://" + Environment.MachineName; 
            GetUserFromAssignedToField(strUrl); 
            // create site context 
            ClientContext ctx = new ClientContext(siteUrl); 
            // create web object 
            Web web = ctx.Web; 
            ctx.Load(web); 
            // get Tasks list 
            List list = ctx.Web.Lists.GetByTitle("MyList"); 
            ctx.Load(list); 
            // get list item using Id e.g. updating first item in the list 
            ListItem targetListItem = list.GetItemById(1); 
            // Load only the assigned to field from the list item 
            ctx.Load(targetListItem, 
                             item => item["AssignedTo"]); 
            ctx.ExecuteQuery(); 
            // create and cast the FieldUserValue from the value 
            FieldUserValue[] fuv = (FieldUserValue[])targetListItem["AssignedTo"]; 
            User user = null; 
            for (int i = 0; i < fuv.Length; i++) 
            { 
                Console.WriteLine("Retrieved user Id is: {0}", fuv[i].LookupId); 
                Console.WriteLine("Retrieved login name is: {0}", fuv[i].LookupValue); 
                user = ctx.Web.EnsureUser(fuv[i].LookupValue); 
                ctx.Load(user); 
                ctx.ExecuteQuery(); 
            } 
            return user; 
        } 

For more detail about CSOM: You can find at on MSDN http://msdn.microsoft.com/en-us/library/office/fp179912(v=office.15).aspx

Hoang Nhut NGUYEN