共用方式為


PublishingWeb.GetPublishingWeb 方法

擷取會指定的SPWeb物件包裝在PublishingWeb的執行個體。

命名空間:  Microsoft.SharePoint.Publishing
組件:  Microsoft.SharePoint.Publishing (在 Microsoft.SharePoint.Publishing.dll 中)

語法

'宣告
Public Shared Function GetPublishingWeb ( _
    web As SPWeb _
) As PublishingWeb
'用途
Dim web As SPWeb
Dim returnValue As PublishingWeb

returnValue = PublishingWeb.GetPublishingWeb(web)
public static PublishingWeb GetPublishingWeb(
    SPWeb web
)

參數

傳回值

類型:Microsoft.SharePoint.Publishing.PublishingWeb
PublishingWeb 執行個體的包裝SPWeb類別。

備註

使用這個方法來存取已擷取的SPWeb類別的執行個體的PublishingWeb行為。您也可以透過GetPublishingWebs方法擷取PublishingWeb類別的執行個體。

使用這個方法之前,請先檢查IsPublishingWeb方法,以確認此SPWeb類別的執行個體上都支援發行行為。如果發行不支援在SPWeb上,然後方法和屬性之PublishingWeb包裝函式可能運作不正常。

它是由這個方法的呼叫端,以關閉 [藉由呼叫SPWeb.Close方法傳入的SPWeb類別的執行個體。呼叫PublishingWeb.Close方法沒有任何作用。

範例

本範例示範如何設定及屬性值儲存在發佈網頁。先建置和執行這個範例中,確認SPWeb中,為已啟用發佈功能,而且defaultPageFileIdSPFile.UniqueId新的預設頁面。

using SPContentTypeId = Microsoft.SharePoint.SPContentTypeId;
using SPContentType = Microsoft.SharePoint.SPContentType;
using SPSite = Microsoft.SharePoint.SPSite;
using SPFile = Microsoft.SharePoint.SPFile;
using SPWeb = Microsoft.SharePoint.SPWeb;
using PublishingSite = Microsoft.SharePoint.Publishing.PublishingSite;
using PublishingWeb = Microsoft.SharePoint.Publishing.PublishingWeb;
using PageLayoutCollection = Microsoft.SharePoint.Publishing.PageLayoutCollection;
using PageLayout = Microsoft.SharePoint.Publishing.PageLayout;

namespace Microsoft.SDK.SharePointServer.Samples
{
    public static class PublishingWebCodeSamples
    {
        public static void SetPublishingWebProperties(SPWeb web, System.Guid defaultPageFileId)
        {
// Replace these variable values and input parameters
// with your own values.
string newTitle = "your Title";         // new PublishingWeb.Title value
string newDescription = "your Description";         // new PublishingWeb.Description value
bool resetInheritPageLayouts = true;    // new PublishingWeb.IsInheritingAvailablePageLayouts value
bool resetInheritWebTemplates = true;   // new PublishingWeb.IsInheritingAvailableWebTemplates value

// Validate the input parameters.
if (null == web)
{
    throw new System.ArgumentNullException("web");
}

// Get the PublishingWeb wrapper for the SPWeb 
// that was passed in.
PublishingWeb publishingWeb = null;
if (PublishingWeb.IsPublishingWeb(web))
{
    publishingWeb = PublishingWeb.GetPublishingWeb(web);
}
else
{
    throw new System.ArgumentException("The SPWeb must be a PublishingWeb", "web");
}

//  Retrieve the SPFile.
SPFile newDefaultPageFile = publishingWeb.Web.GetFile(defaultPageFileId);
if( (null == newDefaultPageFile) ||
    !newDefaultPageFile.Exists )
{
    throw new System.ArgumentException(
        "The Guid does not match an SPFile on the SPWeb",
        "defaultPageFileId");
}

// Set new values on the PublishingWeb.
publishingWeb.Title = newTitle;
publishingWeb.Description = newDescription;
publishingWeb.DefaultPage = newDefaultPageFile;
if( resetInheritPageLayouts && 
    !publishingWeb.IsInheritingAvailablePageLayouts  &&
    !publishingWeb.IsRoot)
{
    publishingWeb.InheritAvailablePageLayouts();
    System.Diagnostics.Debug.Assert(publishingWeb.IsInheritingAvailablePageLayouts);
}
if (resetInheritWebTemplates && 
    !publishingWeb.IsInheritingAvailableWebTemplates &&
    !publishingWeb.IsRoot)
{
    publishingWeb.InheritAvailableWebTemplates();
    System.Diagnostics.Debug.Assert(publishingWeb.IsInheritingAvailableWebTemplates);
}

// Save the new values on the PublishingWeb.
publishingWeb.Update();
        }
    }
}
Imports SPContentTypeId = Microsoft.SharePoint.SPContentTypeId
Imports SPContentType = Microsoft.SharePoint.SPContentType
Imports SPSite = Microsoft.SharePoint.SPSite
Imports SPFile = Microsoft.SharePoint.SPFile
Imports SPWeb = Microsoft.SharePoint.SPWeb
Imports PublishingSite = Microsoft.SharePoint.Publishing.PublishingSite
Imports PublishingWeb = Microsoft.SharePoint.Publishing.PublishingWeb
Imports PageLayoutCollection = Microsoft.SharePoint.Publishing.PageLayoutCollection
Imports PageLayout = Microsoft.SharePoint.Publishing.PageLayout

Namespace Microsoft.SDK.SharePointServer.Samples
    Public NotInheritable Class PublishingWebCodeSamples
        Private Sub New()
        End Sub
        Public Shared Sub SetPublishingWebProperties(ByVal web As SPWeb, ByVal defaultPageFileId As System.Guid)
' Replace these variable values and input parameters
' with your own values.
Dim newTitle As String = "your Title" ' new PublishingWeb.Title value
Dim newDescription As String = "your Description" ' new PublishingWeb.Description value
Dim resetInheritPageLayouts As Boolean = True ' new PublishingWeb.IsInheritingAvailablePageLayouts value
Dim resetInheritWebTemplates As Boolean = True ' new PublishingWeb.IsInheritingAvailableWebTemplates value

' Validate the input parameters.
If Nothing Is web Then
    Throw New System.ArgumentNullException("web")
End If

' Get the PublishingWeb wrapper for the SPWeb 
' that was passed in.
Dim publishingWeb As PublishingWeb = Nothing
If PublishingWeb.IsPublishingWeb(web) Then
    publishingWeb = PublishingWeb.GetPublishingWeb(web)
Else
    Throw New System.ArgumentException("The SPWeb must be a PublishingWeb", "web")
End If

'  Retrieve the SPFile.
Dim newDefaultPageFile As SPFile = publishingWeb.Web.GetFile(defaultPageFileId)
If (Nothing Is newDefaultPageFile) OrElse (Not newDefaultPageFile.Exists) Then
    Throw New System.ArgumentException("The Guid does not match an SPFile on the SPWeb", "defaultPageFileId")
End If

' Set new values on the PublishingWeb.
publishingWeb.Title = newTitle
publishingWeb.Description = newDescription
publishingWeb.DefaultPage = newDefaultPageFile
If resetInheritPageLayouts AndAlso (Not publishingWeb.IsInheritingAvailablePageLayouts) AndAlso (Not publishingWeb.IsRoot) Then
    publishingWeb.InheritAvailablePageLayouts()
    System.Diagnostics.Debug.Assert(publishingWeb.IsInheritingAvailablePageLayouts)
End If
If resetInheritWebTemplates AndAlso (Not publishingWeb.IsInheritingAvailableWebTemplates) AndAlso (Not publishingWeb.IsRoot) Then
    publishingWeb.InheritAvailableWebTemplates()
    System.Diagnostics.Debug.Assert(publishingWeb.IsInheritingAvailableWebTemplates)
End If

' Save the new values on the PublishingWeb.
publishingWeb.Update()
        End Sub
    End Class
End Namespace

請參閱

參照

PublishingWeb 類別

PublishingWeb 成員

Microsoft.SharePoint.Publishing 命名空間