Client Object Model Access Large Lists/Overcome ListView Threshold while accessing large list

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.It is very useful when list view threshhold limit is reached.

static void Main(string[] args)
{
ClientContext clientContext = new ClientContext(“http://testLink”);

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();
}​

Advertisements

One thought on “Client Object Model Access Large Lists/Overcome ListView Threshold while accessing large list

  1. Hello – I have tried out your solution and it seems to work, however I am pulling in multiple versions of each row in the list. I am using Sharepoint 2013 SDK (ver 16). Have you seen this and/or do you know how I can only pull one entry of each row?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s