If you want retrieve large list using Client Object Model. You can use the ListItemCollectionPosition class
to implement paging list item retrieval according to the position of
items relative to their collection. Use the RowLimit element to specify
the number of items to return per page.
Download Working Example
static void Main(string[] args)
{
ClientContext clientContext = new ClientContext("URL Here");
List list = clientContext.Web.Lists.GetByTitle("Tasks");
ListItemCollectionPosition itemPosition = null;
while (true)
{
CamlQuery camlQuery = new CamlQuery();
camlQuery.ListItemCollectionPosition = itemPosition;
camlQuery.ViewXml = @"<View>
<ViewFields>
<FieldRef Name='Title'/>
</ViewFields>
<RowLimit>1</RowLimit>
</View>";
ListItemCollection listItems = list.GetItems(camlQuery);
clientContext.Load(listItems);
clientContext.ExecuteQuery();
itemPosition = listItems.ListItemCollectionPosition;
foreach (ListItem listItem in listItems)
Console.WriteLine("Item Title: {0}", listItem["Title"]);
if (itemPosition == null)
break;
Console.WriteLine(itemPosition.PagingInfo);
Console.WriteLine();
}
Console.ReadLine();
}
Download Working Example
static void Main(string[] args)
{
ClientContext clientContext = new ClientContext("URL Here");
List list = clientContext.Web.Lists.GetByTitle("Tasks");
ListItemCollectionPosition itemPosition = null;
while (true)
{
CamlQuery camlQuery = new CamlQuery();
camlQuery.ListItemCollectionPosition = itemPosition;
camlQuery.ViewXml = @"<View>
<ViewFields>
<FieldRef Name='Title'/>
</ViewFields>
<RowLimit>1</RowLimit>
</View>";
ListItemCollection listItems = list.GetItems(camlQuery);
clientContext.Load(listItems);
clientContext.ExecuteQuery();
itemPosition = listItems.ListItemCollectionPosition;
foreach (ListItem listItem in listItems)
Console.WriteLine("Item Title: {0}", listItem["Title"]);
if (itemPosition == null)
break;
Console.WriteLine(itemPosition.PagingInfo);
Console.WriteLine();
}
Console.ReadLine();
}
No comments:
Post a Comment