Поделиться через


Метод SPContentTypeId.FindCommonParent

Получает идентификатор типа контента (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
)

Параметры

Возвращаемое значение

Тип: Microsoft.SharePoint.SPContentTypeId
Идентификатор типа контента для общей родительской двух идентификаторов типа контента.

Замечания

Общий родительский элемент для идентификаторов всех типов контента — System. Этот метод возвращает идентификатор типа контента, который является на момент в иерархии, где parentage отделения.

For more information about content type lineage, see Base Content Type Hierarchy.

Примеры

В следующем примере показано консольное приложение, которое выполняется поиск общей родительской идентификаторов двух типов контента и имя родительского типа контента. Приложение выведет результатов на консоль.

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...

См. также

Справочные материалы

SPContentTypeId структура

Элементы SPContentTypeId

Пространство имен Microsoft.SharePoint

Другие ресурсы

Content Type IDs

Introduction to Content Types

Site and List Content Types

Base Content Type Hierarchy