Tuesday 12 June 2012

How to get Sharepoint List User Field Value in Silverlight Client Object Model

you can retrieve the user field value in client object model as follows In the below example,i have retrieved all the values from a user column and populated a list box.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace lookupvalue
{

 public partial class MainPage : UserControl
  {
     ClientContext cc;


     public MainPage()
       {

          InitializeComponent();

          cc = new ClientContext(ApplicationContext.Current.Url);

          cc.Load(cc.Web);

          listobj = cc.Web.Lists.GetByTitle("your list name");

          List s = cc.Web.SiteUserInfoList;
 
          cc.Load(listobj);

          CamlQuery cml = new CamlQuery();

          view = "";

          cml.ViewXml = view;

          _lsititemcoll = listobj.GetItems(cml);

          cc.Load(_listitemcoll);

          cc.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(OnRequestSucceeded), null);

       }


      private void OnRequestSucceeded(Object sender,ClientRequestSucceededEventArgs args)
       {
           Dispatcher.BeginInvoke(datacon);
       }



      private void datacon()
       {

           foreach(ListItem li in _listitemcoll)
           {

             FieldUserValue fvalue = li["User FieldColumn name"] as FieldUserValue;

             listBox1.Items.Add(fvalue.LookupValue);

           }

        }

   } 
}

No comments:

Post a Comment