I have a List that stores items in a folder hierarchy.
I notice that SPFolder.Files.Count
is always zero.
Is there a way to find out how many list items are there in a folder?
I have a List that stores items in a folder hierarchy.
I notice that SPFolder.Files.Count
is always zero.
Is there a way to find out how many list items are there in a folder?
I presume you are looking for direct children and not descendants (like items within a sub-folder).
Do you also want to include sub-folders in the count? In which case you can use:
SPFolder.ItemCount
.If you just want only the direct child listItems which are not subfolders then you can do something like the following:
I haven't tried it. You might have to add a where clause to eliminate folders, if the query is returning that.
If you want to include all list-items, even within subfolders, set the
SPQuery.ViewAttributes
field asquery.ViewAttributes = "Scope=\"Recursive\""
;From Microsoft
I wonder if the same applies to SPFolder.ItemCount ?
Did you try to get the SPListItem from the SPFolder and check the values from the SPBuiltInFieldId.ItemChildCount and SPBuiltInFieldId.FolderChildCount fields?
Something like this:
See
SPBuiltInFieldId.ItemChildCount Field
SPBuiltInFieldId.FolderChildCount Field
for more info.