共用方式為


SPContentType.Scope property

取得特定的內容類型的範圍內的最高層級中的伺服器相對 URL。

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'宣告
Public ReadOnly Property Scope As String
    Get
'用途
Dim instance As SPContentType
Dim value As String

value = instance.Scope
public string Scope { get; }

Property value

Type: System.String
伺服器相對 URL。

備註

SPContentType類別所表示的內容型別可為網站與清單層級的SPContentTypeCollection集合列舉。在網站層級集合包含所有的內容類型,您可以套用到站台內的清單。在清單層級集合包含所有已套用至該清單的內容類型。當內容類型套用到清單或文件庫 (特殊類型的清單) 時,在網站層級定義的內容型別被複製到清單內容的型別集合。基於這個原因,可能由同一個站台的許多不同清單中的個別SPContentType物件表示相同的站台層級的內容類型定義。

Scope屬性的值會根據特定的SPContentType物件是否是在網站集合或清單集合而有所不同。對於在網站層級的內容型別集合中的物件, Scope屬性的值會是string ,其中包含網站的伺服器相對 URL。物件的內容型別集合在清單層級中, Scope屬性的值會是 [] 清單中的根資料夾的伺服器相對 URL 的字串。

Examples

下列範例是主控台應用程式,選取 [第一個清單],請在網站上。選取清單中所使用的第一個內容類型並顯示清單的內容型別和其父系內容類型的領域。

Imports System
Imports Microsoft.SharePoint

Module ConsoleApp

    Sub Main()
        Console.WriteLine()

        Dim oSPSite As SPSite = New SPSite("https://localhost")
        Dim oSPWeb As SPWeb = oSPSite.OpenWeb()

        Dim oList As SPList = oSPWeb.Lists(0)
        Dim oContentType As SPContentType = oList.ContentTypes(0)

        Console.WriteLine("Content type name: " + oContentType.Name)
        Console.WriteLine("Content type scope: " + oContentType.Scope)
        Console.WriteLine("Parent type name: " + oContentType.Parent.Name)
        Console.WriteLine("Parent type scope: " + oContentType.Parent.Scope)

        oSPWeb.Dispose()
        oSPSite.Dispose()

        Console.WriteLine()
        Console.Write("Press ENTER to continue...")
        Console.ReadLine()
    End Sub

End Module
using System;
using Microsoft.SharePoint;

namespace MyTest
{
    class ConsoleApp
    {
        static void Main(string[] args)
        {
            Console.WriteLine();
            SPSite oSPSite = new SPSite("https://localhost");
            SPWeb oSPWeb = oSPSite.OpenWeb();


            SPList oList = oSPWeb.Lists[0];
            SPContentType oContentType = oList.ContentTypes[0];

            Console.WriteLine("Content type name: " +  oContentType.Name);
            Console.WriteLine("Content type scope: " + oContentType.Scope);
            Console.WriteLine("Parent type name: " + oContentType.Parent.Name);
            Console.WriteLine("Parent type scope: " + oContentType.Parent.Scope);

            oSPWeb.Dispose();
            oSPSite.Dispose();

            Console.WriteLine();
            Console.Write("Press ENTER to continue...");
            Console.ReadLine();
        }
    }
}

應用程式可能會列印下列輸出到主控台。

Content type name: Announcement
Content type scope: /Lists/Announcements
Parent type name: Announcement
Parent type scope: /

Press ENTER to continue...

請參閱

參照

SPContentType class

SPContentType members

Microsoft.SharePoint namespace

其他資源

Introduction to Content Types

Site and List Content Types

Base Content Type Hierarchy