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

 

Adnan is six time Microsoft MVP (Since 2015) with over 16 years of extensive experience with major expertise on SharePoint, SharePoint based development, Microsoft 365, Microsoft Teams, .Net Platform and Microsoft BI. He is currently working Sr Microsoft Consultant at Olive + Goose. He is MCT Regional Lead for Pakistan Chapter since 2012. He is working on SharePoint for past 12 years and worked on different intranet/intranet solutions for private & govt. sector majorly in United states and Gulf region and have experience of working with multiple Fortune 500 companies. He is a trainer, technology evangelist and also speaks in community forums.

Leave a Reply

One reply on “SharePoint: Difference between List.items.Count and List.ItemCount”

  • August 26, 2017 at 6:02 pm

    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.