Get the SPFieldUser value using Client Object Model in SharePoint 2010

In this article we will be seeing how to get the SPFieldUser value using  aClient Object Model in SharePoint 2010. Description:

I have a custom list named SPList which contains the following columns and data


In this we will see how to get the "Created by" value for a particular item using a Client Object Model. Please refer FieldUserValue for more information.

Client Object Model:

  • Open Visual Studio 2010.

  • On the File Menu, click on New and then click on Project.

  • Select the Console Application template from Installed templates.

  • Check whether the project is targeted to .NET Framework 3.5.

  • Enter the Name for the project and then click on Ok.

  • Right click on the project and then click on Properties.

  • Click on Build tab, and check whether the Platform Target is selected as Any CPU.

  • Add the following references.

a. Microsoft.SharePoint. Client.dll

  • Add the following namespaces.

a. Using Microsoft.SharePoint.Client;

  • Replace Program.cs with the following code.

using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SharePoint.Client; using System. Net;

namespace FieldUserValue { class Program   { static void Main(string[] args)   { ClientContext clientContext = new ClientContext("https://serverName:2010/"); List oList = clientContext.Web.Lists.GetByTitle("SPList"); ListItem item = oList.GetItemById(12);   clientContext.Load(item);   clientContext.ExecuteQuery(); FieldUserValue userValue = item["Author"] as FieldUserValue;            Console.WriteLine(userValue.LookupValue.ToString()); Console.ReadLine();    }  } }

Recent Posts

See All