SPBuiltInContentTypeId class
內建的內容型別會擷取表示識別項 (Id) 的SPContentTypeId物件的類別。
Inheritance hierarchy
System.Object
Microsoft.SharePoint.SPBuiltInContentTypeId
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public NotInheritable Class SPBuiltInContentTypeId
'用途
Dim instance As SPBuiltInContentTypeId
public sealed class SPBuiltInContentTypeId
備註
您可以使用的方式類似於您如何使用列舉型別的成員,這個類別的欄位。
Examples
下列範例是主控台應用程式,會檢查地方使用網站集合中的內建 [項目] 的內容型別。應用程式一開始先建置的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();
}
}
}
應用程式執行時使用小組網站範本所建立的網站,它會列印下列輸出到主控台。
The content type is inherited by 33 site content types and 20 list content types.
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.
請參閱
參照
SPBuiltInContentTypeId members
Microsoft.SharePoint namespace