SharePoint: Difference between List.items.Count and List.ItemCount

Published: Updated: 2 min readSharePoint Server

The basic difference between List.items and List.ItemCount  is that list.items returns total no. of list items excluding folders while list.ItemsCount return total no. items in a list including folders.

Check SPList.ItemCount property

Check SPListItemCollection.Count property

When we compare List.items.Count vs List.ItemCount then one more major difference between them is that List.Items.Count shows only those items which are shared with the current user as item collection is security trimmed whereas List.ItemCount return all items and as it is not security-trimmed.

One more thing is that List.ItemCount is faster because it fetch the information from SPList property instead of building SPListItemCollection.

Deleting List Items throws “Specified argument was out of the range of valid values” Exception

One more thing is that List.ItemCount is faster because it fetch the information from SPList property instead of building SPListItemCollection.

And a good example of this is when you are trying to delete list items through loop using list.Count, you might get “Specified argument was out of the range of valid values” exception because you are deleting the list item from list item collection.

//Delete List items

for (int i = 0; i < list.Items.Count; i++)
{
list.Items[0].Delete();
}

To resolve the issue, use List.ItemCount which gives you the static item count value from list property.

for (int i = 0; i < list.ItemCount; i++)
{
list.Items[0].Delete();
}

Check difference between List.ItemCount and List.Items.Count in below screenshot where I executed a PowerShell Script to generate a report which lists list Item count for all list and libraries. In this picture you can clearly see the difference between them.List.ItemCount vs List.Items.Count

 

Share:
Adnan Amin

Adnan Amin

Adnan Amin is a Microsoft MVP for Microsoft 365 (since 2015) and a Senior Microsoft Consultant. He writes practical guides and PowerShell scripts for SharePoint, OneDrive, Teams and Copilot admins.

More posts by Adnan Amin

One response to “SharePoint: Difference between List.items.Count and List.ItemCount”

  1. We ɑre a group of ѵolunteers and opening
    a new scheme in our community. Your web site provided
    us wіth valuabⅼe information to work on. Yoᥙ havе
    done an impressive ϳob and our entire community will
    be thаnkful to you.

Leave a Reply

Your email address will not be published. Required fields are marked *