Export (0) Print
Expand All

SPContentType.Scope Property

Windows SharePoint Services 3

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)

public string Scope { get; }

Property Value

Type: System.String
A string that contains a server-relative URL.

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.

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.

using System;
using Microsoft.SharePoint;

namespace MyTest
{
    class ConsoleApp
    {
        static void Main(string[] args)
        {
            Console.WriteLine();
            SPSite oSPSite = new SPSite("http://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...

Community Additions

ADD
Show:
© 2014 Microsoft