SPContentType.Parent property

Gets the parent content type of this content type.

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

Syntax

'Declaration
Public ReadOnly Property Parent As SPContentType
    Get
'Usage
Dim instance As SPContentType
Dim value As SPContentType

value = instance.Parent
public SPContentType Parent { get; }

Property value

Type: Microsoft.SharePoint.SPContentType
The parent content type.

Remarks

The value of this property is the content type from which the current content type was derived.

Examples

The following example is a console application that examines the heritage of the built-in Announcement content type. The example gets a reference to the content type, uses that reference to get a reference to its parent content type, and uses that reference to get a reference to the parent’s parent content type (in this case, System). The application then descends the hierarchy, printing the value of each content type’s Name and Id property to the console.

Imports System
Imports Microsoft.SharePoint

Module ConsoleApp

    Sub Main()
        Console.WriteLine()

        Dim oSPSite As SPSite = New SPSite("https://localhost")
        Dim oSPWeb As SPWeb = oSPSite.OpenWeb()

        Dim child As SPContentType = oSPWeb.AvailableContentTypes(SPBuiltInContentTypeId.Announcement)
        Dim parent As SPContentType = child.Parent
        Dim grandparent As SPContentType = parent.Parent

        Console.WriteLine(grandparent.Name + "        " + grandparent.Id.ToString())
        Console.WriteLine(parent.Name + "          " + parent.Id.ToString())
        Console.WriteLine(child.Name + "  " + child.Id.ToString())

        oSPWeb.Dispose()
        oSPSite.Dispose()

        Console.WriteLine()
        Console.Write("Press ENTER to continue...")
        Console.ReadLine()
    End Sub

End Module
using System;
using Microsoft.SharePoint;

namespace Test
{
    class ConsoleApp
    {
        static void Main(string[] args)
        {
            Console.WriteLine();
            SPSite oSPSite = new SPSite("https://localhost");
            SPWeb oSPWeb = oSPSite.OpenWeb();

            SPContentType child = oSPWeb.AvailableContentTypes[SPBuiltInContentTypeId.Announcement];
            SPContentType parent = child.Parent;
            SPContentType grandparent = parent.Parent;

            Console.WriteLine(grandparent.Name + "        " + grandparent.Id.ToString());
            Console.WriteLine(parent.Name + "          " + parent.Id.ToString());
            Console.WriteLine(child.Name + "  " + child.Id.ToString());

            oSPWeb.Dispose();
            oSPSite.Dispose();

            Console.WriteLine();
            Console.Write("Press ENTER to continue...");
            Console.ReadLine();
        }
    }
}

The example application prints the following output to the console.

System        0x
Item          0x01
Announcement  0x0104

Press ENTER to continue...

See also

Reference

SPContentType class

SPContentType members

Microsoft.SharePoint namespace

Other resources

Introduction to Content Types

Site and List Content Types

Base Content Type Hierarchy