SPBuiltInContentTypeId Class

A class that retrieves SPContentTypeId objects that represent identifiers (IDs) for built-in content types.

Inheritance Hierarchy

System.Object
  Microsoft.SharePoint.SPBuiltInContentTypeId

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
Public NotInheritable Class SPBuiltInContentTypeId
'Usage
Dim instance As SPBuiltInContentTypeId
public sealed class SPBuiltInContentTypeId

Remarks

You can use the fields of this class in a way that is similar to how you use members of an enumeration.

Examples

The following example is a console application that examines where the built-in “Item” content type is used in a site collection. The application begins by building a generic list of SPContentTypeUsage objects that contain information about each use of a content type in a site collection. Then it counts the number of times that the content type is used as a site content type and the number of times it is used as a list content type. The results are printed to the console.

Imports System
Imports System.Collections.Generic
Imports Microsoft.SharePoint

Module ConsoleApp
   Sub Main()
      Using siteCollection As SPSite = New SPSite("https://localhost")
         Using rootWeb As SPWeb = siteCollection.RootWeb

            ' Get the content type.
            Dim contentType As SPContentType = _
               rootWeb.AvailableContentTypes(SPBuiltInContentTypeId.Item)

            'Get the usage collection.
            Dim usages As IList(Of SPContentTypeUsage) = _
               SPContentTypeUsage.GetUsages(contentType)

            ' Count the site and list types.
            Dim listTypes As Integer = 0
            Dim siteTypes As Integer = 0
            For Each usage As SPContentTypeUsage In usages
               If usage.IsUrlToList Then
                  listTypes += 1
               Else
                  siteTypes += 1
               End If
            Next usage

            Console.Write("The content type is inherited by {0} site content types", siteTypes)
            Console.WriteLine(" and {0} list content types.", listTypes)

         End Using
      End Using
      Console.Write(vbCrLf + "Press ENTER to continue...")
      Console.ReadLine()
   End Sub

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

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite siteCollection = new SPSite("https://localhost"))
         {
            using (SPWeb rootWeb = siteCollection.RootWeb)
            {
               // Get the content type.
               SPContentType contentType =
                  rootWeb.AvailableContentTypes[SPBuiltInContentTypeId.Item];

               //Get the usage collection.
               IList<SPContentTypeUsage> usages = SPContentTypeUsage.GetUsages(contentType);

               // Count the site and list types.
               int listTypes = 0;
               int siteTypes = 0;
               foreach (SPContentTypeUsage usage in usages)
               {
                  if (usage.IsUrlToList)
                     listTypes++;
                  else
                     siteTypes++;
               }

               Console.Write("The content type is inherited by {0} site content types", siteTypes);
               Console.WriteLine(" and {0} list content types.", listTypes);
            }
         }
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }
   }
}

When the application is run against a Web site created with the Team Site template, it prints the following output to the console.

The content type is inherited by 33 site content types and 20 list content types.

Press ENTER to continue...

Thread Safety

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

See Also

Reference

SPBuiltInContentTypeId Members

Microsoft.SharePoint Namespace

SPContentTypeId

GetUsages(SPContentType)

Other Resources

Content Type IDs

Site and List Content Types

Base Content Type Hierarchy