Share via


SPContentTypeId.FindCommonParent Method

Gets the content type identifier (ID) of the common parent of two content type ID values.

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

Syntax

'Declaration
Public Shared Function FindCommonParent ( _
    id1 As SPContentTypeId, _
    id2 As SPContentTypeId _
) As SPContentTypeId
'Usage
Dim id1 As SPContentTypeId
Dim id2 As SPContentTypeId
Dim returnValue As SPContentTypeId

returnValue = SPContentTypeId.FindCommonParent(id1, _
    id2)
public static SPContentTypeId FindCommonParent(
    SPContentTypeId id1,
    SPContentTypeId id2
)

Parameters

Return Value

Type: Microsoft.SharePoint.SPContentTypeId
The content type ID for the common parent of the two content type IDs.

Remarks

The common parent for all content type IDs is System. This method returns the content type ID that is at the point in the hierarchy where parentage branches.

For more information about content type lineage, see Base Content Type Hierarchy.

Examples

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

Imports System
Imports Microsoft.SharePoint

Module Test
   Sub Main()
      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 parentName As String = String.Empty
      For Each ct As SPContentType In web.AvailableContentTypes
          If parentId = ct.Id Then
             parentName = ct.Name
             Exit For
          End If
      Next ct

      ' 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(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)
      {
            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.
            string parentName = String.Empty;
            foreach (SPContentType ct in web.AvailableContentTypes)
            {
                if (parentId == ct.Id)
                {
                    parentName = ct.Name;
                    break;
                }
            }

            // 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...

See Also

Reference

SPContentTypeId Structure

SPContentTypeId Members

Microsoft.SharePoint Namespace

Other Resources

Content Type IDs

Introduction to Content Types

Site and List Content Types

Base Content Type Hierarchy