SPContentTypeUsage.GetUsages-Methode

Gibt eine Liste von SPContentTypeUsage -Objekten mit Informationen zu, in denen der angegebene Inhaltstyp verwendet wird.

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

Syntax

'Declaration
Public Shared Function GetUsages ( _
    contentType As SPContentType _
) As IList(Of SPContentTypeUsage)
'Usage
Dim contentType As SPContentType
Dim returnValue As IList(Of SPContentTypeUsage)

returnValue = SPContentTypeUsage.GetUsages(contentType)
public static IList<SPContentTypeUsage> GetUsages(
    SPContentType contentType
)

Parameter

Rückgabewert

Typ: System.Collections.Generic.IList<SPContentTypeUsage>
Eine Auflistung von SPContentTypeUsage -Objekten.

Hinweise

Diese Methode gibt eine generische Liste von SPContentTypeUsage -Objekten, die Informationen zu jeder Verwendung eines Inhaltstyps in der Websitesammlung enthalten. Wenn der Inhaltstyp nicht verwendet wird, gibt die Methode eine leere Liste (Count = 0).

Hinweis

Ein Inhaltstyp wird "verwendet", wenn alle davon abgeleiteten Inhaltstyp in einer Website oder Liste Ebene an einer beliebigen Stelle innerhalb seines Bereichs SPContentTypeCollection -Auflistung vorhanden ist. Weitere Informationen finden Sie unter Content Type Scope.

Beispiele

Das folgende Beispiel ist eine Konsolenanwendung, die versehen werden die Usage-Auflistung für die integrierten Inhaltstypen "Item". Die Anwendung zählt die Anzahl der Male, die sie als einem Websiteinhaltstyp verwendet wird und wie oft es als einem Listeninhaltstyp verwendet wird, und klicken Sie dann druckt die Summen in der Konsole angezeigt.

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

Module ConsoleApp
   Sub Main()
      Using siteCollection As SPSite = New SPSite("https://localhost")
         Using rootWeb As SPWeb = siteCollection.RootWeb

            ' Get the content type.
            Dim contentType As SPContentType = _
               rootWeb.AvailableContentTypes(SPBuiltInContentTypeId.Item)

            'Get the usage collection.
            Dim usages As IList(Of SPContentTypeUsage) = _
               SPContentTypeUsage.GetUsages(contentType)

            ' Count the site and list types.
            Dim listTypes As Integer = 0
            Dim siteTypes As Integer = 0
            For Each usage As SPContentTypeUsage In usages
               If usage.IsUrlToList Then
                  listTypes += 1
               Else
                  siteTypes += 1
               End If
            Next usage

            Console.Write("The content type is inherited by {0} site content types", siteTypes)
            Console.WriteLine(" and {0} list content types.", listTypes)

         End Using
      End Using
      Console.Write(vbCrLf + "Press ENTER to continue...")
      Console.ReadLine()
   End Sub

End Module
using System;
using System.Collections.Generic;
using Microsoft.SharePoint;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite siteCollection = new SPSite("https://localhost"))
         {
            using (SPWeb rootWeb = siteCollection.RootWeb)
            {
               // Get the content type.
               SPContentType contentType =
                  rootWeb.AvailableContentTypes[SPBuiltInContentTypeId.Item];

               //Get the usage collection.
               IList<SPContentTypeUsage> usages = SPContentTypeUsage.GetUsages(contentType);

               // Count the site and list types.
               int listTypes = 0;
               int siteTypes = 0;
               foreach (SPContentTypeUsage usage in usages)
               {
                  if (usage.IsUrlToList)
                     listTypes++;
                  else
                     siteTypes++;
               }

               Console.Write("The content type is inherited by {0} site content types", siteTypes);
               Console.WriteLine(" and {0} list content types.", listTypes);
            }
         }
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }
   }
}

Wenn die Anwendung auf einer Website mit der Vorlage Teamwebsite erstellte ausgeführt wird, druckt es die folgende Ausgabe in der Konsole angezeigt.

The content type is inherited by 33 site content types and 20 list content types.

Press ENTER to continue...

Siehe auch

Referenz

SPContentTypeUsage Klasse

SPContentTypeUsage-Member

Microsoft.SharePoint-Namespace

Weitere Ressourcen

Site and List Content Types

Creating Content Types Based on Other Content Types