SPContentType.ParentWeb property
取得父網站的內容類型。
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public ReadOnly Property ParentWeb As SPWeb
Get
'用途
Dim instance As SPContentType
Dim value As SPWeb
value = instance.ParentWeb
public SPWeb ParentWeb { get; }
Property value
Type: Microsoft.SharePoint.SPWeb
父網站之內。
備註
ParentWeb屬性的值是SPWeb物件,表示網站所在的SPContentType物件。值是相同的所有網站,不論是否在網站或清單層級範圍中存在的任何地方的SPContentType物件。
Examples
下列範例是一個主控台應用程式,列舉列印到主控台的每個清單的名稱在站台中,所有的清單。此外,範例程式碼會列舉每個清單的內容類型,列印到主控台,以及伺服器相對 URL 的每個內容型別名稱的內容類型的父 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();
}
}
}
某些列印到主控台的輸出看起來可能像這樣:
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: /
請參閱
參照
Microsoft.SharePoint namespace