Compartilhar via


SPContentTypeId.FindCommonParent method

Obtém o identificador de tipo de conteúdo (ID) do pai comum de dois valores de identificação de tipo de conteúdo.

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

Syntax

'Declaração
Public Shared Function FindCommonParent ( _
    id1 As SPContentTypeId, _
    id2 As SPContentTypeId _
) As SPContentTypeId
'Uso
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
)

Parâmetros

Valor retornado

Type: Microsoft.SharePoint.SPContentTypeId
A ID de tipo de conteúdo comuns das duas identificações de tipo de conteúdo pai.

Comentários

O pai comum para tipo de conteúdo de todos os IDs é System. Esse método retorna a ID de tipo de conteúdo que estiver no ponto da hierarquia onde parentage filiais.

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

Examples

O exemplo a seguir mostra um aplicativo de console que localiza o pai comum de tipo de conteúdo duas IDs e o nome do tipo de conteúdo pai. O aplicativo imprime o resultado no console.

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

O aplicativo imprime a seguinte saída no console.

ID of Message is       0x0107
ID of Discussion is    0x012002
Their common parent is 0x01 (Item)

Press ENTER to continue...

Ver também

Referência

SPContentTypeId structure

SPContentTypeId members

Microsoft.SharePoint namespace

Outros recursos

Content Type IDs

Introduction to Content Types

Site and List Content Types

Base Content Type Hierarchy