SPBuiltInContentTypeId.Contains method

Determines whether a specified content type identifier (ID) belongs to a built-in content type.

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

public static bool Contains(
	SPContentTypeId contentTypeId
)

Parameters

contentTypeId
Type: Microsoft.SharePoint.SPContentTypeId

An SPContentTypeId object.

Return value

Type: System.Boolean
true if the content type ID applies to a built-in content type; otherwise false.

This method returns true only when the content type ID that is passed as an argument is an exact match with a built-in content type ID. This method returns false when the method is passed a content type ID that is derived from a built-in type. For example, when a built-in content type is applied to a list, the list version of the content type is given a new content type ID. If you pass the new content type ID as an argument to the Contains method, it returns false.

The following example shows a console application that enumerates the available content types, determines which content types are not built-in, and prints the names of those content types to the console.

using System;
using Microsoft.SharePoint;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite siteCollection = new SPSite("http://localhost"))
         {
            using (SPWeb webSite = siteCollection.OpenWeb())
            {
               // Find the content types that are not built-in.
               foreach (SPContentType ct in webSite.AvailableContentTypes)
               {
                  bool BuiltIn = SPBuiltInContentTypeId.Contains(ct.Id);
                  if (!BuiltIn)
                     Console.WriteLine(ct.Name);
               }
            }
         }
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }
   }
}
Show: