次の方法で共有


SPContentType.Scope property

Gets a server-relative URL for the highest level within the scope of a particular content type.

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

Syntax

'Declaration
Public ReadOnly Property Scope As String
    Get
'Usage
Dim instance As SPContentType
Dim value As String

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

Property value

Type: System.String
A server-relative URL.

Remarks

Content types that are represented by the SPContentType class can be enumerated as SPContentTypeCollection collections at both the site and list level. The collection at the site level contains all the content types that you can apply to lists within the site. The collection at the list level contains all the content types that have been applied to that list. When a content type is applied to a list or document library (a special type of list), a content type defined at the site level is copied to the list’s content type collection. For this reason, the same site-level content type definition might be represented by separate SPContentType objects in many different lists within the same site.

The value of the Scope property varies depending on whether a particular SPContentType object is in a site collection or list collection. For objects in the content type collection at the site level, the value of the Scope property is a string that contains a server-relative URL for the Web site. For objects in a content type collection at the list level, the value of the Scope property is a string with a server-relative URL for the root folder of the list.

Examples

The following example is a console application that selects the first list in a Web site; selects the first content type used in the list; and displays the scopes for the list content type and its parent content type.

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();
        }
    }
}

The application might print the following output to the console.

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

Press ENTER to continue...

See also

Reference

SPContentType class

SPContentType members

Microsoft.SharePoint namespace

Other resources

Introduction to Content Types

Site and List Content Types

Base Content Type Hierarchy