Share via


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)

Syntax

<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class SPBuiltInContentTypeId

Dim instance As SPBuiltInContentTypeId
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class SPBuiltInContentTypeId

Remarks

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

Examples

The following example shows a console application that finds both the common parent of two content type IDs and the name of the parent content type. It also prints the result to the console.

Imports System
Imports Microsoft.SharePoint

Module Test
   Sub Main()
      Using site As SPSite = New SPSite("http://localhost")
         Using web As SPWeb = site.OpenWeb()

            Dim x As SPContentTypeId = SPBuiltInContentTypeId.Message
            Dim y As SPContentTypeId = SPBuiltInContentTypeId.Discussion

            ' Get the parent content type ID.
            Dim parentId As SPContentTypeId = SPContentTypeId.FindCommonParent(x, y)

            ' Get the parent content type name.
            Dim ct As SPContentType = web.AvailableContentTypes(parentId)
            Dim parentName As String = ct.Name

            ' Display the result.
            Console.WriteLine("ID of Message is       {0}", x.ToString())
            Console.WriteLine("ID of Discussion is    {0}", y.ToString())
            Console.WriteLine("Their common parent is {0} ({1})", _
                              parentId.ToString(), parentName)

         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 site = new SPSite("http://localhost"))
         {
            using (SPWeb web = site.OpenWeb())
            {
               SPContentTypeId x = SPBuiltInContentTypeId.Message;
               SPContentTypeId y = SPBuiltInContentTypeId.Discussion;

               // Get the parent content type ID.
               SPContentTypeId parentId = SPContentTypeId.FindCommonParent(x, y);
               
               // Get the parent content type name.
               SPContentType ct = web.AvailableContentTypes[parentId];
               string parentName = ct.Name;

               // Display the result.
               Console.WriteLine("ID of Message is       {0}", x.ToString());
               Console.WriteLine("ID of Discussion is    {0}", y.ToString());
               Console.WriteLine("Their common parent is {0} ({1})", 
                                  parentId.ToString(), parentName);
            }
         }
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }
   }
}

The application prints the following output to the console.

ID of Message is       0x0107
ID of Discussion is    0x012002
Their common parent is 0x01 (Item)

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

Other Resources

Content Type IDs

Site and List Content Types

Base Content Type Hierarchy