SPContentTypeId 结构

表示内容类型的标识符 (ID)。

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

语法

声明
<SerializableAttribute> _
Public Structure SPContentTypeId _
    Implements IComparable
用法
Dim instance As SPContentTypeId
[SerializableAttribute]
public struct SPContentTypeId : IComparable

备注

内容类型 Id 唯一标识内容类型,并旨在成为递归。内容类型 ID 封装继承关系的内容类型或内容类型继承父内容类型的行。每个内容类型 ID 包含 ID 的父内容类型,这又包含了该内容类型的父级的 ID 和等,最终回,并包括System内容类型 id。

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

示例

下面的示例演示一个控制台应用程序,用五个内置内容类型 Id 填充数组的数组的每个成员共有数组的其他成员的后代进行计数。它也将打印到控制台其字符串值。

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

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

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...

线程安全性

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

另请参阅

引用

SPContentTypeId 成员

Microsoft.SharePoint 命名空间

Id

SPBuiltInContentTypeId

其他资源

Content Type IDs

Introduction to Content Types

Site and List Content Types

Base Content Type Hierarchy