Retrieve A List Item In Sharepoint Using CSOM-ItemPosition Method

Steps
  1. Open Visual Studio in your system.
  2. Select Console Application template and give the name as "Enablefolder".
  3. Add a Microsoft.Cleint Assembly reference file in right side reference tab in Visual Studio.
  4. Replace Program.cs with the source code given below.
In this snippet, ListItemCollectionPosition class is given to implement paging list item retrieval, according to the position of items, which are relative to their collection. We can use the Row limit to return the number of the items per page.

Code snippet
  1. using System;  
  2. using Microsoft.SharePoint.Client;  
  3.   
  4.   
  5. namespace GowthamArticles  
  6. {  
  7.     class itemPositiontItem  
  8.     {  
  9.         static void Main()  
  10.         {     
  11.               
  12.             ClientContext clientContext = new ClientContext("https://gowtham.sharepoint.com/tutorials");  
  13.             List oList = clientContext.Web.Lists.GetByTitle("Announcements");  
  14.   
  15.             ListItemCollectionPosition itemPosition = null;  
  16.   
  17.             while (true)  
  18.             {  
  19.                 CamlQuery Query = new CamlQuery();  
  20.                 camlQuery.ListItemCollectionPosition = itemPosition;  
  21.                 camlQuery.ViewXml = "<View><ViewFields><FieldRef Name='ID'/>" +   
  22.                     "<FieldRef Name='Title'/><FieldRef Name='Body'/>" +   
  23.                     "</ViewFields><RowLimit>10</RowLimit></View>";  
  24.   
  25.                 ListItemCollection ocollListItem = oList.GetItems(Query);  
  26.                 clientContext.Load(0collListItem);  
  27.             clientContext.ExecuteQuery();   
  28.         }  
  29.     }  
  30. }