SPContentTypeId.FindCommonParent 方法
获取两个内容类型 ID 值的通用父内容类型标识符 (ID)。
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public Shared Function FindCommonParent ( _
id1 As SPContentTypeId, _
id2 As SPContentTypeId _
) As SPContentTypeId
用法
Dim id1 As SPContentTypeId
Dim id2 As SPContentTypeId
Dim returnValue As SPContentTypeId
returnValue = SPContentTypeId.FindCommonParent(id1, _
id2)
public static SPContentTypeId FindCommonParent(
SPContentTypeId id1,
SPContentTypeId id2
)
参数
id1
类型:Microsoft.SharePoint.SPContentTypeId两个内容类型 Id 的第一个。
id2
类型:Microsoft.SharePoint.SPContentTypeId两个内容的第二个键入 Id。
返回值
类型:Microsoft.SharePoint.SPContentTypeId
两个内容类型 Id 的通用父内容类型 ID。
备注
所有内容类型 Id 的常见父级是System。此方法返回位于层次结构中的点其中 parentage 分支的内容类型 ID。
For more information about content type lineage, see Base Content Type Hierarchy.
示例
下面的示例演示的控制台应用程序查找两个内容类型 Id 的通用父对象的父内容类型的名称。应用程序打印至控制台的结果。
Imports System
Imports Microsoft.SharePoint
Module Test
Sub Main()
Dim x As SPContentTypeId = SPBuiltInContentTypeId.Message
Dim y As SPContentTypeId = SPBuiltInContentTypeId.Discussion
' Get the parent content type ID.
Dim parentId As SPContentTypeId = SPContentTypeId.FindCommonParent(x, y)
' Get the parent content type name.
Dim parentName As String = String.Empty
For Each ct As SPContentType In web.AvailableContentTypes
If parentId = ct.Id Then
parentName = ct.Name
Exit For
End If
Next ct
' Display the result.
Console.WriteLine("ID of Message is {0}", x.ToString())
Console.WriteLine("ID of Discussion is {0}", y.ToString())
Console.WriteLine("Their common parent is {0} ({1})", parentId.ToString(), parentName)
Console.Write(vbCrLf + "Press ENTER to continue...")
Console.ReadLine()
End Sub
End Module
using System;
using Microsoft.SharePoint;
namespace Test
{
class ConsoleApp
{
static void Main(string[] args)
{
SPContentTypeId x = SPBuiltInContentTypeId.Message;
SPContentTypeId y = SPBuiltInContentTypeId.Discussion;
// Get the parent content type ID.
SPContentTypeId parentId = SPContentTypeId.FindCommonParent(x, y);
// Get the parent content type name.
string parentName = String.Empty;
foreach (SPContentType ct in web.AvailableContentTypes)
{
if (parentId == ct.Id)
{
parentName = ct.Name;
break;
}
}
// Display the result.
Console.WriteLine("ID of Message is {0}", x.ToString());
Console.WriteLine("ID of Discussion is {0}", y.ToString());
Console.WriteLine("Their common parent is {0} ({1})", parentId.ToString(), parentName);
Console.Write("\nPress ENTER to continue...");
Console.ReadLine();
}
}
}
应用程序将以下输出显示到控制台上。
ID of Message is 0x0107
ID of Discussion is 0x012002
Their common parent is 0x01 (Item)
Press ENTER to continue...