Share via


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)

Syntax

'Declaration
Public Shared Function Contains ( _
    contentTypeId As SPContentTypeId _
) As Boolean
'Usage
Dim contentTypeId As SPContentTypeId
Dim returnValue As Boolean

returnValue = SPBuiltInContentTypeId.Contains(contentTypeId)
public static bool Contains(
    SPContentTypeId contentTypeId
)

Parameters

Return value

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

Remarks

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.

Examples

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.

Imports System
Imports Microsoft.SharePoint

Module ConsoleApp

   Sub Main()
      Using siteCollection As SPSite = New SPSite("https://localhost")
         Using webSite As SPWeb = siteCollection.OpenWeb()

            ' Find the content types that are not built-in.
            For Each ct As SPContentType In webSite.AvailableContentTypes
               Dim BuiltIn As Boolean = _
                   SPBuiltInContentTypeId.Contains(ct.Id)
               If Not BuiltIn Then
                  Console.WriteLine(ct.Name)
               End If
            Next ct

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

End Module
using System;
using Microsoft.SharePoint;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite siteCollection = new SPSite("https://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();
      }
   }
}

See also

Reference

SPBuiltInContentTypeId class

SPBuiltInContentTypeId members

Microsoft.SharePoint namespace

Other resources

Content Type IDs

Site and List Content Types

Base Content Type Hierarchy