Returning SharePoint Folder Item Count In C#
A question was posted on the newsgroups on how to build a reusable method that could return the item count from a specified folder, here is one that works just fine:
- private int GetItemsForFolderInt(SPFolder folder)
- {
- int i = folder.Files.Count;
- foreach (SPFolder myFolder in ((IEnumerable) folder.SubFolders))
- {
- i += GetItemsForFolderInt(myFolder);
- }
- return i;
- }
So, you would of course have to use recursion and recall the method itself within the declaration, and the output of this would just an integer.
:-)
Articles & Research
SharePoint Security
SharePoint Development
SharePoint Architecture
Claims Authentication
Forefront For SharePoint
AIS / Dynamics GP
Team Foundation Server
Pex And Moles
ISA/TMG/IAG/UAG
DPM
Cardspace
Research Methodology
Rural ICT Development
Numerical Analysis
Multi-Level Research
Knowledge Management
Personal/Off-Topic