Monday 16 April 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 Microsoft.SharePoint.Client.CamlQuery();
view = "<view/>";
cml.ViewXml = view;
_lsititemcoll = listobj.GetItems(cml);
cc.Load(_listitemcoll);
cc.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(OnRequestSucceeded), null);

}
private void OnRequestSucceeded(Object sender, ClientRequestSucceededEventArgs args)
{

// This is not called on the UI thread.
Dispatcher.BeginInvoke(datacon);

}
private void datacon()
{
foreach(ListItem li in _listitemcoll)
{

FieldUserValue  fvalue  =   li["User Field column  name"]  as  FieldUserValue;
listBox1.Items.Add(fvalue.LookupValue);

}
}
}

No comments:

Post a Comment