SPContentType.Id property
取得SPContentTypeId物件,表示內容類型的內容型別識別項 (ID)。
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public ReadOnly Property Id As SPContentTypeId
Get
'用途
Dim instance As SPContentType
Dim value As SPContentTypeId
value = instance.Id
public SPContentTypeId Id { get; }
Property value
Type: Microsoft.SharePoint.SPContentTypeId
內容類型識別碼。
備註
內容型別識別碼識別內容類型,以及專為遞迴。內容的型別 ID 會封裝該內容類型的歷程或內容的型別所繼承的父系內容類型的列。每個內容的型別 ID 包含父系內容類型,依序回最後包含該內容類型的父代,依此類推,ID ID,並包括 [系統內容中,輸入 id。剖析的內容型別 ID,可以判斷相關內容的型別繼承,哪些內容類型和兩個內容類型。
如需詳細資訊,請參閱Content Type IDs。
Examples
下列範例是主控台應用程式,可以搜尋的網站有內建文件的內容型別,其內容的型別集合中的清單。當找到相符的項目時,應用程式是列印父系內容類型識別碼,並在主控台的相符內容的型別 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...
請參閱
參照
Microsoft.SharePoint namespace