SPContentType.Parent Property
SharePoint 2010
Gets the parent content type of this content type.
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
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...