Partilhar via


SPContentTypeId.IsParentOf Method

Indicates whether the current content type identifier (ID) is a parent of the specified content type ID.

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

Syntax

'Declaration
Public Function IsParentOf ( _
    id As SPContentTypeId _
) As Boolean
'Usage
Dim instance As SPContentTypeId
Dim id As SPContentTypeId
Dim returnValue As Boolean

returnValue = instance.IsParentOf(id)
public bool IsParentOf(
    SPContentTypeId id
)

Parameters

Return Value

Type: System.Boolean
true if the current content type ID is a parent of the ID passed as an argument; otherwise, false.

Remarks

This method returns true for all descendants of the current content type ID. (For information about content type ID lineage, see Base Content Type Hierarchy.) For example, each of the last two lines of code in the following example contains an expression that evaluates to true.

SPContentTypeId x = SPBuiltInContentTypeId.Item;
SPContentTypeId y = SPBuiltInContentTypeId.Document;
SPContentTypeId z = SPBuiltInContentTypeId.BasicPage;

Console.WriteLine(x.IsParentOf(y)); // True
Console.WriteLine(x.IsParentOf(z)); // True
Dim x As SPContentTypeId = SPBuiltInContentTypeId.Item
Dim y As SPContentTypeId = SPBuiltInContentTypeId.Document
Dim z As SPContentTypeId = SPBuiltInContentTypeId.BasicPage

Console.WriteLine(x.IsParentOf(y)) ' True
Console.WriteLine(x.IsParentOf(z)) ' True

In addition, the method returns true if the value of the content type ID passed in as an argument is the same as the value of the current content type ID, as shown in the following example.

x = y;
Console.WriteLine(x == y);           // True
Console.WriteLine(x.IsParentOf(y));  // True
Console.WriteLine(y.IsParentOf(x));  // True
x = y
Console.WriteLine(x = y) ' True
Console.WriteLine(x.IsParentOf(y)) ' True
Console.WriteLine(y.IsParentOf(x)) ' True

This behavior is consistent with the behavior of the IsChildOf method, which also returns true when the value of the object passed in as an argument is the same as the value of the current object.

To determine the immediate parent of a content type ID, use the Parent property.

See Also

Reference

SPContentTypeId Structure

SPContentTypeId Members

Microsoft.SharePoint Namespace

Parent

FindCommonParent

IsChildOf

Other Resources

Content Type IDs

Base Content Type Hierarchy