次の方法で共有


SPContentType.ParentWeb property

Gets the parent Web site for the content type.

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

Syntax

'Declaration
Public ReadOnly Property ParentWeb As SPWeb
    Get
'Usage
Dim instance As SPContentType
Dim value As SPWeb

value = instance.ParentWeb
public SPWeb ParentWeb { get; }

Property value

Type: Microsoft.SharePoint.SPWeb
The parent Web site.

Remarks

The value of the ParentWeb property is an SPWeb object that represents the Web site where the SPContentType object exists. The value is the same for all SPContentType objects that exist anywhere within the Web site, no matter whether they are scoped at the site or list level.

Examples

The following example is a console application that enumerates all lists in a site, printing the name of each list to the console. In addition, the example code enumerates each list’s content types, printing the name of each content type to the console as well as a server-relative URL for the content type’s parent Web.

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 oListCollection As SPListCollection = oSPWeb.Lists

        For Each oList As SPList In oListCollection
            Console.WriteLine("List title: " + oList.Title)
            Console.WriteLine()
            For Each oContentType As SPContentType In oList.ContentTypes
                Console.WriteLine("   Content type name: " + oContentType.Name)
                Dim oParent As SPWeb = oContentType.ParentWeb
                Console.WriteLine("   Content type's parent Web: " + oParent.ServerRelativeUrl)
                Console.WriteLine()
                oParent.Dispose()
            Next
        Next

        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();
            SPListCollection oListCollection = oSPWeb.Lists;

            foreach (SPList oList in oListCollection)
            {
                Console.WriteLine("List title: " + oList.Title);
                Console.WriteLine();
                foreach (SPContentType oContentType in oList.ContentTypes)
                {
                    Console.WriteLine("   Content type name: " + oContentType.Name);
                    SPWeb oParent = oContentType.ParentWeb;
                    Console.WriteLine("   Content type's parent Web: " + oParent.ServerRelativeUrl);
                    Console.WriteLine();
                    oParent.Dispose();
                }
                Console.WriteLine();
            }

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

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

Some of the output printed to the console might look like this:

List title: Announcements

   Content type name: Announcement
   Content type's parent Web: /

   Content type name: Folder
   Content type's parent Web: /


List title: Calendar

   Content type name: Event
   Content type's parent Web: /


List title: Links

   Content type name: Link
   Content type's parent Web: /

   Content type name: Folder
   Content type's parent Web: /

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