SPContentTypeId structure

Represents the identifier (ID) of a content type.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

public struct SPContentTypeId : IComparable

Content type IDs uniquely identify the content type and are designed to be recursive. The content type ID encapsulates the lineage of a content type or the line of parent content types from which the content type inherits. Each content type ID contains the ID of the parent content type, which in turn contains the ID of that content type's parent, and so on, ultimately back to and including the System content type ID.

For more information, see Content Type IDs and the Id property.

The following example shows a console application that fills an array with five built-in content type IDs and counts the number of descendants each member of the array has in common with other members of the array. It also prints their string values to the console.

using System;
using System.Collections.Generic;
using Microsoft.SharePoint;

namespace ConsoleApp
    class Program
        static void Main(string[] args)
            // Fill an array with SPContentTypeId objects.
            List<SPContentTypeId> ids = new List<SPContentTypeId>

            // Display the hex strings.
            Console.WriteLine("The list has {0} content type IDs:", ids.Count.ToString());
            foreach (SPContentTypeId id in ids) Console.WriteLine("{0}", id.ToString());

            // Show the lineage.
            for (int i = 0; i < ids.Count; i++)
                SPContentTypeId parent = ids[i];
                int children = 0;
                for (int j = 0; j < ids.Count; j++)
                    SPContentTypeId id = ids[j];
                    if (id.IsChildOf(parent) && id != parent)
                Console.WriteLine("{0} descendants of {1}", children.ToString(), ids[i].ToString());


            Console.Write("\nPress ENTER to continue....");

The application prints the following output to the console.

The list has 5 content type IDs:

4 descendants of 0x
3 descendants of 0x01
2 descendants of 0x0101
1 descendants of 0x010109
0 descendants of 0x01010901

Press ENTER to continue...

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.