How to get SharePoint List Items through SharePoint Client Object Model
- Iterate List Items
ClientContext clientContext = new ClientContext("Site URL");
NetworkCredential Cred = new NetworkCredential("UserName", "Password", "Domain");
clientContext.Credentials = Cred;
Web web = clientContext.Web;
Microsoft.SharePoint.Client.List lst = clientContext.Web.Lists.GetByTitle("List Name");
ListCollection fieldList = web.Lists;
clientContext.Load(fieldList);
// Execute the query to the server.
clientContext.ExecuteQuery();
foreach (Microsoft.SharePoint.Client.List lstobj in fieldList)
{
Console.WriteLine("\n"+"Title:" + lstobj.Title);
Console.WriteLine("Description:" + lstobj.Description);
Console.WriteLine("Created:" + lstobj.Created);
Console.WriteLine("\n");
}
Console.ReadLine();
- SharePoint List Item count
ClientContext clientContext = new ClientContext("Site URL");
NetworkCredential Cred = new NetworkCredential("UserName", "Password", "Domain");
clientContext.Credentials = Cred;
Web web = clientContext.Web;
Microsoft.SharePoint.Client.List lst = clientContext.Web.Lists.GetByTitle("List Name");
clientContext.Load(lst);
clientContext.ExecuteQuery();
int cnt = lst.ItemCount;
Console.WriteLine(cnt);
Console.ReadLine();