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.
One reply on “SharePoint: Difference between List.items.Count and List.ItemCount”
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.