SPContentType.ParentWeb 属性

获取父网站的内容类型。

命名空间:  Microsoft.SharePoint
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
Public ReadOnly Property ParentWeb As SPWeb
    Get
用法
Dim instance As SPContentType
Dim value As SPWeb

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

属性值

类型:Microsoft.SharePoint.SPWeb
父网站。

备注

ParentWeb属性的值是一个SPWeb对象,表示网站SPContentType对象存在。值为相同的网站,无论是否在网站或列表级别范围内的任意位置存在的所有SPContentType对象。

示例

下面的示例是一个控制台应用程序,枚举网站中的所有列表打印到控制台的每个列表的名称。此外,该代码示例枚举每个列表内容类型、 内容类型的父网站的打印到控制台以及相对于服务器的 URL 的每个内容类型的名称。

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

打印到控制台的输出的一些可能如下所示:

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: /

另请参阅

引用

SPContentType 类

SPContentType 成员

Microsoft.SharePoint 命名空间

其他资源

Introduction to Content Types

Site and List Content Types

Base Content Type Hierarchy