SPContentType.Id-Eigenschaft

Ruft ein SPContentTypeId -Objekt, das den Inhaltstypbezeichner (ID) des Inhaltstyps darstellt.

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

Syntax

'Declaration
Public ReadOnly Property Id As SPContentTypeId
    Get
'Usage
Dim instance As SPContentType
Dim value As SPContentTypeId

value = instance.Id
public SPContentTypeId Id { get; }

Eigenschaftswert

Typ: Microsoft.SharePoint.SPContentTypeId
Die Inhaltstyp-ID

Hinweise

Inhaltstyp-IDs Identifizieren von Inhaltstypen und rekursiv sein sollen. Die Inhaltstyp-ID kapselt diesen Inhaltstyp Herkunft oder die Zeile der übergeordneten Inhaltstypen, die von denen der Inhaltstyp erbt. Jeder Inhaltstyp-ID enthält die ID des den übergeordneten Inhaltstyp, der wiederum die ID des übergeordneten diesen Inhaltstyp und usw., letztlich wieder auf enthält, und geben das Systeminhalt eingeschlossen ID. Durch die Inhaltstyp-ID analysieren, können Sie bestimmen, welche Inhaltstypen der Inhaltstyp erbt, und wie zwei Inhaltstypen in Verbindung stehen.

Weitere Informationen finden Sie unter Content Type IDs.

Beispiele

Das folgende Beispiel ist eine Konsolenanwendung, die eine Website für Listen durchsucht, die die integrierten Dokumentinhaltstyp in ihre inhaltstypauflistung haben. Wenn eine Übereinstimmung gefunden wird, wird die Anwendung der übergeordnete Inhaltstyp-ID und die entsprechenden Inhaltstyp-ID in der Konsole gedruckt.

Imports System
Imports Microsoft.SharePoint

Module Test
   Sub Main()
      Using site As SPSite = New SPSite("https://localhost")
         Using web As SPWeb = site.OpenWeb()

            ' Search for a built-in content type on lists in the site.
            Dim parentId As SPContentTypeId = SPBuiltInContentTypeId.Document

            For Each list As SPList In web.Lists
               Dim matchId As SPContentTypeId = _
                  list.ContentTypes.BestMatch(parentId)
               ' Report a match only if the list is not hidden
               ' (e.g. Master Page Gallery).
               If parentId.IsParentOf(matchId) And Not list.Hidden Then
                  Console.WriteLine("{0} has the {1} content type.", _
                                     list.Title, _
                                     list.ContentTypes(matchId).Name)
                  Console.WriteLine("parent content type id: {0}", _
                                     parentId.ToString())
                  Console.WriteLine("  list content type id: {0}",_
                                     matchId.ToString())
               End If
            Next list
         End Using
      End Using
      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)
      {
         using (SPSite site = new SPSite("https://localhost"))
         {
            using (SPWeb web = site.OpenWeb())
            {
               // Search for a built-in content type on lists in the site.
               SPContentTypeId parentId = SPBuiltInContentTypeId.Document;
               foreach (SPList list in web.Lists)
               {
                  SPContentTypeId matchId = 
                     list.ContentTypes.BestMatch(parentId);
                  // Report a match only if the list is not hidden 
                  // (e.g. Master Page Gallery).
                  if (parentId.IsParentOf(matchId) && !list.Hidden)
                  {
                     Console.WriteLine("{0} has the {1} content type.",
                                        list.Title, 
                                        list.ContentTypes[matchId].Name);
                     Console.WriteLine("parent content type id: {0}",
                                        parentId.ToString());
                     Console.WriteLine("  list content type id: {0}", 
                                        matchId.ToString());
                  }
               }
            }
         }
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }
   }
}

Die folgende Ausgabe wird in der Konsole angezeigt.

Shared Documents has the Document content type.
parent content type id: 0x0101
  list content type id: 0x010100C21DAAD3BCD4FF409A4DB5005BF7E12F

Press ENTER to continue...

Siehe auch

Referenz

SPContentType Klasse

SPContentType-Member

Microsoft.SharePoint-Namespace

Weitere Ressourcen

Content Type IDs

Introduction to Content Types

Site and List Content Types

Base Content Type Hierarchy