This documentation is archived and is not being maintained.

SPContentType.Id Property

Windows SharePoint Services 3

Gets an SPContentTypeId object that represents the content type ID of the content type.

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

public SPContentTypeId Id { get; }

Content type IDs uniquely identify the content type and are designed to be recursive. The content type ID encapsulates that content type's lineage, 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. By parsing the content type ID, you can determine which content types the content type inherits, and how two content types are related.

For more information, see Content Type IDs.

The following example is a console application that searches a site for lists that have the built-in Document content type in their content type collection. When a match is found, the application prints the parent content type’s Id and the matching content type’s Id to the console.

using System;
using Microsoft.SharePoint;

namespace Test
   class ConsoleApp
      static void Main(string[] args)
         using (SPSite site = new SPSite("http://localhost"))
            using (SPWeb web = site.OpenWeb())
               // Search for a built-in content type on lists in the site.
               SPContentTypeId parentId = SPBuiltInContentTypeId.Document;
               foreach (SPList list in web.Lists)
                  SPContentTypeId matchId = 
                  // Report a match only if the list is not hidden 
                  // (e.g. Master Page Gallery).
                  if (parentId.IsParentOf(matchId) && !list.Hidden)
                     Console.WriteLine("{0} has the {1} content type.",
                     Console.WriteLine("parent content type id: {0}",
                     Console.WriteLine("  list content type id: {0}", 
         Console.Write("\nPress ENTER to continue...");

The application prints the following output to the console.

Shared Documents has the Document content type.
parent content type id: 0x0101
  list content type id: 0x010100C21DAAD3BCD4FF409A4DB5005BF7E12F

Press ENTER to continue...