Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

A list on my site gives 2 when I call myList.ItemCount. But myList.Items.Count gives me zero and I can't access the items stored in the list. AllItems.aspx show me the two missing items.

Any ideas?

share|improve this question
add comment

6 Answers 6

I remember that @furuknap once pointed out that ItemCount and Items.Count are different in the way they treat SPFolders (inclusive and exclusive). Also, ItemCount is faster because it gets a static SPList property instead of building the SPListItemCollection object before counting its members.

share|improve this answer
add comment

I looked closely with Reflector and found this, SPList.Items returns the list items by running a query with Scope=Recursive ViewAttribute. I don't have enough time to do some research on the topic but simply running a query with no attributes gave me my items.

share|improve this answer
2  
remember it is a best practice to use myList.ItemCount over myList.Items.Count, for performance reasons. Read more here blog.dynatrace.com/2009/01/08/… –  Anders Rask Feb 23 '10 at 20:02
add comment

Permissions might be the issue. I ran into the same thing, and it turned out that I forgot to make the list accessible.

http://stackoverflow.com/questions/3823338/why-cant-i-access-the-items-in-a-list-even-if-the-splist-itemcount-is-0

share|improve this answer
add comment

Check whether the user u logged in may not assigned in ur site collection..... i too meet the same problem.... now cleared.....

add the u user what u logged in to the site collection and then check it....

share|improve this answer
    
Welcome to SharePoint StackExchange. Although your answer may answer the question, links to blog posts often break, where as we won't be going anywhere for a long while. It's always a good idea to extract the useful parts for research if not all of it incase that happens (If it's not too long!) Please read the FAQ[1] for more information [1]:sharepoint.stackexchange.com/faq –  Hugh Wood Dec 2 '12 at 3:18
add comment

SPList.ItemCount is the efficient and recommended way to retrieve items count in a list.

However, It should be noted that this property is fine tuned for performance which may cause the side effect of returning unexpected count. So, if you need the exact count, you should use the poorer performing SPList.Items.Count or SPList.GetItems(SPQuery query).Count

share|improve this answer
add comment

SPList.ItemCount, which is count of all items in the list. SPList.Items.Count, which is count of completed tasks/Check In pages. (Means it avoid the incompleted items)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.