I am trying to get the count of the number of items in a SPFolder. I have tried several things so far however they seem to break once I add two subfolders. I want the total number of files in all folders contained within the top level folder (excluding folders as part of the total).
Example Folder Structure:
-Business Plans - 4 Files
--Archives - 1 File
---2012 - 1 File
What I have Tried (fldr = BusinessPlans in these scenarios):
//Example A:
SPQuery query = new SPQuery();
query.Folder = fldr;
SPListItemCollection allitems = list.GetItems(query);
int filecount = allitems.Count;
//Example B:
int filecount = fldr.Files.Count;
//Example C:
int filecount = fldr.ItemCount;
All seem to return filecount = 5
Any idea what I am doing wrong here or do I have to write a recursive function that total all the files up?