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, a distinguished professional, boasts an impressive track record as a Microsoft MVP, having achieved this prestigious recognition for the eighth consecutive year since 2015. With an extensive career spanning over 18 years, Adnan has honed his expertise in various domains, notably excelling in SharePoint, Microsoft 365, Microsoft Teams, the .Net Platform, and Microsoft BI. Presently, he holds the esteemed position of Senior Microsoft Consultant at Olive + Goose. Notably, Adnan served as the MCT Regional Lead for the Pakistan Chapter from 2012 to 2017, showcasing his leadership and commitment to fostering growth within the tech community. His journey in the realm of SharePoint spans 14 years, during which he has undertaken diverse projects involving both intranet and internet solutions for both private and government sectors. His impact has transcended geographical boundaries, leaving a mark on projects in the United States and the Gulf region, often collaborating with Fortune 500 companies. Beyond his roles, Adnan is a dedicated educator, sharing his insights and knowledge as a trainer. He also passionately advocates for technology, frequently engaging with the community through speaking engagements in various forums. His multifaceted contributions exemplify his dedication to the tech field and his role in driving its evolution.

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.