Friday, May 20, 2016

How to load all fields for a specific ListItem using Client Object Model



string str="Peakfinder";
string strlist="Employee";
Web web = context.Site.OpenWebById(str); 
List list = web.Lists.GetByTitle(strlist);
string queryTxt = "<View><Query><Where><Contains><FieldRef Name=\"Title\" /><Value Type=\"Text\">Auto</Value></Contains></Where></Query></View>"; 
CamlQuery query = new CamlQuery(); 
query.ViewXml = queryTxt;
ListItemCollection listItems = list.GetItems(query);

context.Load(listItems, items => items.Include(item => item.Id,item => item["Title"], item => item["Name"], item => item["Design"])); 
context.ExecuteQuery();

foreach (ListItem item in listItems) 
{
Console.WriteLine("Item ID = " + item.Id + " Title = " + item["Title"] + " helloworld= " + item["Name"] + " myField= " + item["Design"]);


No comments:

Post a Comment