SPContentTypeUsage.GetUsages method
傳回SPContentTypeUsage物件指定的內容型別正在使用中的相關資訊的清單。
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public Shared Function GetUsages ( _
contentType As SPContentType _
) As IList(Of SPContentTypeUsage)
'用途
Dim contentType As SPContentType
Dim returnValue As IList(Of SPContentTypeUsage)
returnValue = SPContentTypeUsage.GetUsages(contentType)
public static IList<SPContentTypeUsage> GetUsages(
SPContentType contentType
)
參數
contentType
Type: Microsoft.SharePoint.SPContentType要追蹤的內容型別。
傳回值
Type: System.Collections.Generic.IList<SPContentTypeUsage>
SPContentTypeUsage物件的集合。
備註
這個方法會傳回SPContentTypeUsage物件包含每種使用方式的相關資訊的網站集合中的內容型別泛型清單。如果未使用的內容類型,這個方法會傳回空的清單 (Count = 0)。
注意事項 |
---|
內容類型是 「 使用 」 從它衍生的任何內容類型是否有在網站或清單層級,其範圍內的任何地方SPContentTypeCollection集合中。如需詳細資訊,請參閱Content Type Scope。 |
Examples
下列範例是一個主控台應用程式,取得使用集合,內建的內容型別 [項目]。應用程式會計算它做為站台的內容類型的次數和時間,它做為清單的內容類型,並接著會列印到主控台的總計數目。
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...
請參閱
參照
Microsoft.SharePoint namespace