SPContentType.Id 属性

获取一个SPContentTypeId对象,表示内容类型的内容类型标识符 (ID)。

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

语法

声明
Public ReadOnly Property Id As SPContentTypeId
    Get
用法
Dim instance As SPContentType
Dim value As SPContentTypeId

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

属性值

类型:Microsoft.SharePoint.SPContentTypeId
内容类型 id。

备注

内容类型 Id 标识内容类型,并旨在成为递归。内容类型 ID 封装该内容类型沿袭或内容类型继承父内容类型的行。每个内容类型 ID 包含父内容类型,后者又回最终包含该内容类型的父级,等) 的 ID 的 ID,并包括系统的内容类型 id。通过分析的内容类型 ID,您可以确定相关的内容类型继承,哪些内容类型和如何两个内容类型。

For more information, see Content Type IDs.

示例

下面的示例是一个控制台应用程序中搜索其内容类型集合中具有内置的文档内容类型的列表的网站。当找到匹配项时,应用程序将打印的父内容类型 ID 和到控制台的匹配内容类型 ID。

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

应用程序将以下输出显示到控制台上。

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

Press ENTER to continue...

另请参阅

引用

SPContentType 类

SPContentType 成员

Microsoft.SharePoint 命名空间

其他资源

Content Type IDs

Introduction to Content Types

Site and List Content Types

Base Content Type Hierarchy