Showing Child-Items Count in hierarchical SharePoint Lists with multiple content-types
SharePoint 2007 introduced content-types to template standard record definitions and re-use them across lists, such as Task, Issue, or even Folder. Multiple such content-types can be set associated to a single list. A folder is a content-type as well, and it can not only have child items/files within it but also have extended columns just like any item. This allows interesting scenario's where-by instead of using Lookups to setup relationship of items spread across lists one can implicitly set master-detail relationship on items within same lists.
I want to share how can you show the number of items within such folder (or master item!) without actually opening it. This is often useful when you want to give a view to users or have compute column at Master level without going deep into Details level.
ItemChildCount
This is a column in SharePoint database that keeps track of child items to a folder. When building a custom list definition or to an existing list, you can update list schema to include custom Field that is a lookup to ItemChildCount. Syntax is:
1: <Field ID="{REPLACE YOUR GUID HERE}"
2: Name="ItemChildCount"
3: DisplayName="# of Items"
4: DisplaceOnUpgrade="TRUE"
5: SourceID="http://schemas.microsoft.com/sharepoint/v3"
6: StaticName="ItemChildCount"
7: Group="_Hidden"
8: ReadOnly="TRUE"
9: Filterable="FALSE"
10: Sortable="FALSE"
11: Hidden="FALSE"
12: Type="Lookup"
13: List="Docs"
14: FieldRef="ID"
15: ShowField="ItemChildCount"
16: JoinColName="DoclibRowId" JoinRowOrdinal="0" JoinType="INNER" />
Above should be included in Schema.xml of your list definition, or you can update existing list by object model. If you do not have access to deploy code on your SharePoint site, say in a corporate Intranet setup, you can still update your custom list schema by Web Service by adding above field.
In a future post I'll share some details on enabling various scenario's by use of multiple content-types within same list, and its usability benefits on SharePoint sites.
-- Sharad