Ads

Tuesday, 28 March 2017

Difference between SPList.ItemCount and SPList.Items.Count

SPList.ItemCount:
  1. If you want to get the count of list items including folder and sub folder,use SPList.ItemCount property of the list.
  2. Performance wise  SPList.ItemCount  is faster as it is static property of SPList.
  3. SPList.ItemCount not required as such permission.

SPList.Items.Count:
  1. The SPList.Items property returns all the files in a document library/List, including files in sub folders, but not the folders themselves. SPList.Items returns the list items by running a query with Scope=Recursive ViewAttribute.Hence if you want to get only the count of items then use SPList.Items.Count
  2. As SharePoint provide item level permission,to use SPList.Items.Count code must be running with the full permission else it will result into access denied.
  3. SPList.Items is slower as it has to  first get the data then do the counting.
However SPList.ItemCount occasionally return unexpected results.so It is best practice is to use one of the GetItem* methods of SPList to return a filtered collection of items.

No comments:

Post a Comment

Ads