SPContentTypeId structure
代表內容類型識別碼 (ID)。
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
<SerializableAttribute> _
Public Structure SPContentTypeId _
Implements IComparable
'用途
Dim instance As SPContentTypeId
[SerializableAttribute]
public struct SPContentTypeId : IComparable
備註
內容類型識別碼唯一識別此內容類型及設計用來為遞迴。內容類型識別碼封裝內容類型的歷程或上層內容類型的內容類型繼承的列。每個內容類型識別碼包含 ID 的上層內容類型,其接著會包含該內容類型與其父系的識別碼及等,最終後,且包含System內容輸入 id。
For more information, see Content Type IDs and the Id property.
Examples
下列範例會顯示主控台應用程式的五個內建內容類型識別碼填滿的陣列,並計算的下階陣列的每個成員具有通用其他成員陣列的數目。它也會列印主控台其字串值。
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...
Thread safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
請參閱
參照
Microsoft.SharePoint namespace