0

I get the view limit exception when I make a request to the SharePoint online api that has more than 5K items in the view. I want to be able to count the number of items in the view without returning those items (thereby bypassing the exception).

Here is the ViewXml template that I use:

<View>
  <RowLimit>1000</RowLimit>
  <Query>
    <Where>
      <And>
        <Geq>
          <FieldRef Name="{2}"></FieldRef>
          <Value Type="DateTime">{0:yyyy-MM-dd}</Value>
        </Geq>
        <Leq>
          <FieldRef Name="{2}"></FieldRef>
          <Value Type="DateTime">{1:yyyy-MM-dd}</Value>
        </Leq>
      </And>
    </Where>
  </Query>
</View>

0

The answer is "no". There is no way to check for the number of items returned by a View. There is List.ItemCount but it will return the number of items in the list. Unfiltered.

If you need the number of items returned by the View you'll need to get the items and count them. Use "paging" to get around the 5K-Limit.

  • You can use RowLimit in the CAML, to stay below 5K
  • CamlQuery, as well as ListItemCollection has a ListItemCollectionPosition which is null when all items are read..

... so you'd need something along the lines of:

$list = Get-MyCoolList
$query = New-Object Microsoft.SharePoint.Client.CamlQuery
$query.ViewXml = "<View><Query><Where>...</Where></Query><RowLimit>4999</RowLimit></View>";
do {
  $items = $list.GetItems($query);
  $query.ListItemCollectionPosition = $items.ListItemCollectionPosition;

  #  ... do cool stuff...

} while ($query.ListItemCollectionPosition -ne $null)
  • I use a Row Limit of 1,000 actually but I'm still getting the error. – user77232 May 21 at 21:20
  • So, how do you access SharePoint? REST? – Nils May 22 at 5:07
  • I use the CSOM. I just can't seem to figure out why I'm getting the view limit. – user77232 May 22 at 14:23
0

When the list contains more than 5000 items, the columns you are querying must be indexed.

https://www.codeproject.com/Articles/1076854/Overcoming-the-List-View-Threshold-in-SharePoint-C

This solves my problem, but doesn't answer my original question. I would still like to know if there is a way to get the count without having to download all the rows.

  • Ah. I didn't see that coming. Views are simply a "filter". If your list contains more than 5000 items, you have to build a query/view that a) uses only indexed columns to do the filtering and b) returns less than 5000 items. – Nils May 22 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.