SPContentTypeId - Structure

Représente l'identificateur (ID) d'un type de contenu.

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

Syntaxe

'Déclaration
<SerializableAttribute> _
Public Structure SPContentTypeId _
    Implements IComparable
'Utilisation
Dim instance As SPContentTypeId
[SerializableAttribute]
public struct SPContentTypeId : IComparable

Remarques

ID de type de contenu unique identifie le type de contenu et est conçus pour être récursive. L'ID de type de contenu encapsule l'enregistrement en ligne d'un type de contenu ou de la ligne de types de contenu parent dont hérite du type de contenu. Chaque ID de type de contenu contient l'ID du type de contenu parent, qui à son tour contient l'ID de parent de ce type contenu et ainsi de suite, en dernier ressort back, y compris le contenu System tapez ID.

For more information, see Content Type IDs and the Id property.

Exemples

L'exemple suivant montre une application console qui remplit un tableau avec cinq types de contenu prédéfinis ID et compte le nombre de descendants de que chaque membre du tableau a en commun avec d'autres membres du tableau. Il imprime également leurs valeurs de chaîne dans la console.

Imports System
Imports System.Collections.Generic
Imports Microsoft.SharePoint

Module ConsoleApp

    Sub Main()

        ' Fill an array with SPContentTypeId objects.
        Dim ids As New List(Of SPContentTypeId)
        ids.Add(SPBuiltInContentTypeId.System)
        ids.Add(SPBuiltInContentTypeId.Item)
        ids.Add(SPBuiltInContentTypeId.Document)
        ids.Add(SPBuiltInContentTypeId.BasicPage)
        ids.Add(SPBuiltInContentTypeId.WebPartPage)

        ' Display the hex strings.
        Console.WriteLine("The list has {0} content type IDs:", ids.Count.ToString())
        For Each id As SPContentTypeId In ids
            Console.WriteLine("{0}", id.ToString())
        Next

        ' Show the lineage.
        Console.WriteLine()
        For i As Integer = 0 To ids.Count - 1
            Dim parent As SPContentTypeId = ids(i)
            Dim children As Integer = 0
            For j As Integer = 0 To ids.Count - 1
                Dim id As SPContentTypeId = ids(j)
                If id.IsChildOf(parent) And id <> parent Then
                    children += 1
                End If
            Next
            Console.WriteLine("{0} descendants of {1}", children.ToString(), ids(i).ToString())
        Next

        Console.Write(vbCrLf & "Press ENTER to continue....")
        Console.Read()
    End Sub
End Module
using System;
using System.Collections.Generic;
using Microsoft.SharePoint;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            // Fill an array with SPContentTypeId objects.
            List<SPContentTypeId> ids = new List<SPContentTypeId>
               { 
                  SPBuiltInContentTypeId.System,
                  SPBuiltInContentTypeId.Item,
                  SPBuiltInContentTypeId.Document, 
                  SPBuiltInContentTypeId.BasicPage, 
                  SPBuiltInContentTypeId.WebPartPage
               };

            // Display the hex strings.
            Console.WriteLine("The list has {0} content type IDs:", ids.Count.ToString());
            foreach (SPContentTypeId id in ids) Console.WriteLine("{0}", id.ToString());

            // Show the lineage.
            Console.WriteLine();
            for (int i = 0; i < ids.Count; i++)
            {
                SPContentTypeId parent = ids[i];
                int children = 0;
                for (int j = 0; j < ids.Count; j++)
                {
                    SPContentTypeId id = ids[j];
                    if (id.IsChildOf(parent) && id != parent)
                        children++;
                }
                Console.WriteLine("{0} descendants of {1}", children.ToString(), ids[i].ToString());

            }

            Console.Write("\nPress ENTER to continue....");
            Console.Read();
        }
    }
}

L'application imprime la sortie suivante sur la console.

The list has 5 content type IDs:
0x
0x01
0x0101
0x010109
0x01010901

4 descendants of 0x
3 descendants of 0x01
2 descendants of 0x0101
1 descendants of 0x010109
0 descendants of 0x01010901

Press ENTER to continue...

Cohérence de thread

Tous les membres statique (Partagé dans Visual Basic)s publics de ce type sont thread-safe. Cela n’est pas garanti pour les membres d’instance.

Voir aussi

Référence

SPContentTypeId - Membres

Microsoft.SharePoint - Espace de noms

Id

SPBuiltInContentTypeId

Autres ressources

Content Type IDs

Introduction to Content Types

Site and List Content Types

Base Content Type Hierarchy