SPBuiltInContentTypeId 类

一个内置内容类型检索表示标识符 (Id) 的SPContentTypeId对象的类。

继承层次结构

System.Object
  Microsoft.SharePoint.SPBuiltInContentTypeId

命名空间:  Microsoft.SharePoint
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
Public NotInheritable Class SPBuiltInContentTypeId
用法
Dim instance As SPBuiltInContentTypeId
public sealed class SPBuiltInContentTypeId

备注

您可以使用此类以一种类似于您如何使用枚举成员的字段。

示例

下面的示例是一个控制台应用程序来检查内置的"项"内容类型使用在站点集合中的位置。应用程序通过构建包含信息的每次使用内容类型在网站集的SPContentTypeUsage对象的泛型列表开始。然后该函数计算的次数,以用作网站内容类型的内容类型和它用作列表内容类型的次数。结果输出到控制台。

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

对使用工作组网站模板创建一个 Web 站点运行应用程序时,它会输出以下输出到控制台。

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

Press ENTER to continue...

线程安全性

该类型的任何公共 静态 (已共享 在 Visual Basic 中) 成员都是线程安全的。不保证任何实例成员都是线程安全的。

另请参阅

引用

SPBuiltInContentTypeId 成员

Microsoft.SharePoint 命名空间

SPContentTypeId

GetUsages(SPContentType)

其他资源

Content Type IDs

Site and List Content Types

Base Content Type Hierarchy