共用方式為


SPContentType.Parent property

取得此內容的父系內容類型輸入。

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

Syntax

'宣告
Public ReadOnly Property Parent As SPContentType
    Get
'用途
Dim instance As SPContentType
Dim value As SPContentType

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

Property value

Type: Microsoft.SharePoint.SPContentType
父系內容類型。

備註

這個屬性的值是目前的內容型別衍生的內容類型。

Examples

下列範例是主控台應用程式,檢查內建的Announcement內容類型的相似性。範例會取得內容型別的參考,使用該參考來取得其父系內容類型的參考並使用該參考來取得父項的父系內容類型的參考 (在這個案例中, System)。應用程式接著降移的階層架構中,然後再列印到主控台的每個內容類型的NameId屬性的值。

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();
        }
    }
}

範例應用程式會列印下列輸出到主控台。

System        0x
Item          0x01
Announcement  0x0104

Press ENTER to continue...

請參閱

參照

SPContentType class

SPContentType members

Microsoft.SharePoint namespace

其他資源

Introduction to Content Types

Site and List Content Types

Base Content Type Hierarchy