SIGN UP MEMBER LOGIN:    
ARTICLE

Get the SPFieldUserValueCollection values using Client Object Model in SharePoint 2010

Posted by Vijai Anand Articles | SharePoint September 07, 2011
In this article we will be seeing how to get the SPFieldUserValueCollection values using a Client Object Model in SharePoint 2010.
Reader Level:

In this article we will be seeing how to get the SPFieldUserValueCollection values using a Client Object Model in SharePoint 2010.

Description:

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

Client Object Model in SharePoint 2010

The MultiUser column is created using a Person or Group field type and Allow Multiple Selections option is enabled.

Client Object Model in SharePoint 2010

In this we will see how to get the MultiUser column value for a particular item which is a SPFieldUserValueCollection using a Client Object Model.

Client Object Model:

  1. Open Visual Studio 2010.
  2. On the File Menu, click on New and then click on Project.
  3. Select  theConsole Application template from Installed templates.
  4. Check whether the project is targeted to .NET Framework 3.5.
  5. Enter the Name for the project and then click on Ok.
  6. Right click on the project and then click on Properties.
  7. Click on Build tab, and check whether the Platform Target is selected as Any CPU.
  8. Add the following references.

    • Microsoft.SharePoint.Client.dll
     
  9. Add the following namespaces.

    • Using Microsoft.SharePoint.Client;

  10. 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();
                foreach (FieldUserValue userValue in item["MultiUser"]as FieldUserValue[])
                {
                    Console.WriteLine(userValue.LookupValue.ToString());
                }
                Console.ReadLine();
            }
        }
    }
     

  11. Build the solution.

  12. Hit F5.

  13. Output:

    Client Object Model in SharePoint 2010 Output


Note: Please refer FieldUserValue for more information.

Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Nevron Gauge for SharePoint
Become a Sponsor