Partager via


SPContentTypeId.FindCommonParent - Méthode

Obtient l'identificateur de type de contenu (ID) du parent commun de deux valeurs d'ID de type de contenu.

Espace de noms :  Microsoft.SharePoint
Assembly :  Microsoft.SharePoint (dans Microsoft.SharePoint.dll)

Syntaxe

'Déclaration
Public Shared Function FindCommonParent ( _
    id1 As SPContentTypeId, _
    id2 As SPContentTypeId _
) As SPContentTypeId
'Utilisation
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
)

Paramètres

Valeur renvoyée

Type : Microsoft.SharePoint.SPContentTypeId
ID du type de contenu parent commun des deux ID de type de contenu.

Remarques

Le parent commun pour tous les ID de type contenu est System. Cette méthode renvoie l'ID de type de contenu qui est au niveau du point dans la hiérarchie de branchement où d'origine.

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

Exemples

L'exemple suivant montre une application console qui permet de rechercher le parent commun du type de contenu de deux ID et le nom du type de contenu parent. L'application imprime le résultat à la 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();
      }
   }
}

L'application imprime la sortie suivante sur la console.

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

Press ENTER to continue...

Voir aussi

Référence

SPContentTypeId structure

SPContentTypeId - Membres

Microsoft.SharePoint - Espace de noms

Autres ressources

Content Type IDs

Introduction to Content Types

Site and List Content Types

Base Content Type Hierarchy