Export (0) Print
Expand All

SPContentType.Parent property

Gets the parent content type of this content type.

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

public SPContentType Parent { get; }

Property value

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

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

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.

using System;
using Microsoft.SharePoint;

namespace Test
{
    class ConsoleApp
    {
        static void Main(string[] args)
        {
            Console.WriteLine();
            SPSite oSPSite = new SPSite("http://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...
Show:
© 2014 Microsoft