Compartilhar via


PublishingPage.Layout propriedade

Obtém e define o PageLayout para este objeto PublishingPage .

Namespace:  Microsoft.SharePoint.Publishing
Assembly:  Microsoft.SharePoint.Publishing (em Microsoft.SharePoint.Publishing.dll)

Sintaxe

'Declaração
Public Property Layout As PageLayout
    Get
    Set
'Uso
Dim instance As PublishingPage
Dim value As PageLayout

value = instance.Layout

instance.Layout = value
public PageLayout Layout { get; set; }

Valor de propriedade

Tipo: Microsoft.SharePoint.Publishing.PageLayout
PageLayout para este objeto PublishingPage .

Exceções

Exceção Condição
[System.ArgumentException]

PageLayout.AssociatedContentType não coincide com o PublishingPage.ContentType

[System.UnauthorizedAccessException]

O usuário atual não tem permissões suficientes para executar essa ação.

[System.ArgumentNullException]

Indica que o valor que está sendo definido foi uma referência nula (Nothing no Visual Basic), que não é válido.

Comentários

A propriedade Layout fornece informações de renderização para o PublishingPagee corresponde a ContentType. Suporte a processamento de conteúdo definido pelo objeto SPContentType .

O valor de PublishingPage.Layout é inicializado quando um PublishingPage é criado (consulte [M:Microsoft.SharePoint.Publishing.PublishingPageCollection.Add(System.String,Microsoft.SharePoint.Publishing.PageLayout]). Ao contrário do objeto PublishingPage.ContentType , você pode modificar o PublishingPage.Layout após a criação. Somente PageLayouts que estão associados a atual PublishingPage.ContentType são válidas. Se você tentar definir um layout que não é válido, o sistema gera uma exceção de System.ArgumentException .

O PageLayout geralmente deve ser um membro do PageLayoutCollection que é retornado pelo método Publishing.GetAvailablePageLayouts(SPContentType) , mas SharePoint 2010 não impor isso.

O PageLayout pode retornar uma referência nula (Nothing no Visual Basic) se o PublishingPage estiver desconectado de seu objeto PageLayout .

Para salvar as alterações após a definição dessa propriedade, você deve chamar o método Update .

Para definir esse valor, o usuário deverá ter ambos exibir e editar permissões do PublishingPage, exibir permissões para recuperar a página e para retornar os seus valores de propriedade e editar permissões para alterar o valor.

Exemplos

Este exemplo substitui o objeto PageLayout para todos os objetos PublishingPage em uma Web para um novo PageLayout que processa o mesmo tipo de conteúdo.

Antes de compilação e a execução deste exemplo, verifique se que o oldPageLayout e newPageLayout renderizar o mesmo conteúdo. Eles devem usar o mesmo valor de AssociatedContentType .

using PublishingPage = Microsoft.SharePoint.Publishing.PublishingPage;
using SPListItem = Microsoft.SharePoint.SPListItem;
using SPFile = Microsoft.SharePoint.SPFile;
using SPModerationStatusType = Microsoft.SharePoint.SPModerationStatusType;
using PublishingWeb = Microsoft.SharePoint.Publishing.PublishingWeb;
using SPUser = Microsoft.SharePoint.SPUser;
using PageLayout = Microsoft.SharePoint.Publishing.PageLayout;
using PublishingPageCollection = Microsoft.SharePoint.Publishing.PublishingPageCollection;

namespace Microsoft.SDK.SharePointServer.Samples
{
    public static class PublishingPageCodeSamples
    {
        public static void SwapPageLayout(PublishingWeb publishingWeb, PageLayout oldPageLayout, PageLayout newPageLayout)
        {
            // Replace these variable values and input parameters
            // with your own values.
            //
            // The comment to set when the page is checked in, published, and
            // approved.
            string checkInComment = "Your comments";
            //
            // Validate the input parameters.
            if (null == publishingWeb)
            {
                throw new System.ArgumentNullException("publishingWeb");
            }
            if (null == oldPageLayout)
            {
                throw new System.ArgumentNullException("oldPageLayout");
            }
            if (null == newPageLayout)
            {
                throw new System.ArgumentNullException("newPageLayout");
            }
            // Confirm that the oldPageLayout and newPageLayout are compatible.
            if (oldPageLayout.AssociatedContentType.Id != newPageLayout.AssociatedContentType.Id)
            {
                throw new System.ArgumentException(
                    "The page layouts must render the same type of content",
                    "newPageLayout");
            }

            System.Guid oldPageLayoutId = oldPageLayout.ListItem.File.UniqueId;

            // Set the new PageLayout for all pages that use the old PageLayout.
            PublishingPageCollection publishingPages = publishingWeb.GetPublishingPages();
            foreach (PublishingPage publishingPage in publishingPages)
            {
                if (publishingPage.Layout.ListItem.UniqueId == oldPageLayoutId)
                {
                    if (publishingPage.ListItem.File.CheckOutStatus == SPFile.SPCheckOutStatus.None)
                    {
                        publishingPage.CheckOut();
                    }

                    publishingPage.Layout = newPageLayout;
                    publishingPage.Update();

                    // The PublishingPage has the same SPContentType as its PageLayout.
                    System.Diagnostics.Debug.Assert(
                        publishingPage.ContentType.Parent.Id ==
                        newPageLayout.AssociatedContentType.Id);

                    publishingPage.CheckIn(checkInComment);
                }
            }

        }

    }
}
Imports PublishingPage = Microsoft.SharePoint.Publishing.PublishingPage
Imports SPListItem = Microsoft.SharePoint.SPListItem
Imports SPFile = Microsoft.SharePoint.SPFile
Imports SPModerationStatusType = Microsoft.SharePoint.SPModerationStatusType
Imports PublishingWeb = Microsoft.SharePoint.Publishing.PublishingWeb
Imports SPUser = Microsoft.SharePoint.SPUser
Imports PageLayout = Microsoft.SharePoint.Publishing.PageLayout
Imports PublishingPageCollection = Microsoft.SharePoint.Publishing.PublishingPageCollection

Namespace Microsoft.SDK.SharePointServer.Samples
    Public NotInheritable Class PublishingPageCodeSamples
        Private Sub New()
        End Sub
        Public Shared Sub SwapPageLayout(ByVal publishingWeb As PublishingWeb, ByVal oldPageLayout As PageLayout, ByVal newPageLayout As PageLayout)
            ' Replace these variable values and input parameters
            ' with your own values.
            '
            ' The comment to set when the page is checked in, published, and
            ' approved.
            Dim checkInComment As String = "Your comments"
            '
            ' Validate the input parameters.
            If Nothing Is publishingWeb Then
                Throw New System.ArgumentNullException("publishingWeb")
            End If
            If Nothing Is oldPageLayout Then
                Throw New System.ArgumentNullException("oldPageLayout")
            End If
            If Nothing Is newPageLayout Then
                Throw New System.ArgumentNullException("newPageLayout")
            End If
            ' Confirm that the oldPageLayout and newPageLayout are compatible.
            If oldPageLayout.AssociatedContentType.Id <> newPageLayout.AssociatedContentType.Id Then
                Throw New System.ArgumentException("The page layouts must render the same type of content", "newPageLayout")
            End If

            Dim oldPageLayoutId As System.Guid = oldPageLayout.ListItem.File.UniqueId

            ' Set the new PageLayout for all pages that use the old PageLayout.
            Dim publishingPages As PublishingPageCollection = publishingWeb.GetPublishingPages()
            For Each publishingPage As PublishingPage In publishingPages
                If publishingPage.Layout.ListItem.UniqueId = oldPageLayoutId Then
                    If publishingPage.ListItem.File.CheckOutStatus = SPFile.SPCheckOutStatus.None Then
                        publishingPage.CheckOut()
                    End If

                    publishingPage.Layout = newPageLayout
                    publishingPage.Update()

                    ' The PublishingPage has the same SPContentType as its PageLayout.
                    System.Diagnostics.Debug.Assert(publishingPage.ContentType.Parent.Id = newPageLayout.AssociatedContentType.Id)

                    publishingPage.CheckIn(checkInComment)
                End If
            Next publishingPage

        End Sub

    End Class
End Namespace

Ver também

Referência

PublishingPage classe

PublishingPage membros

Microsoft.SharePoint.Publishing namespace