Partager via


PageLayout - Constructeur

Utilise la classe SPListItem pour construire un objet d'élément de liste PageLayout dans une bibliothèque de documents.

Espace de noms :  Microsoft.SharePoint.Publishing
Assembly :  Microsoft.SharePoint.Publishing (dans Microsoft.SharePoint.Publishing.dll)

Syntaxe

'Déclaration
Public Sub New ( _
    listItem As SPListItem _
)
'Utilisation
Dim listItem As SPListItem

Dim instance As New PageLayout(listItem)
public PageLayout(
    SPListItem listItem
)

Paramètres

Exceptions

Exception Condition
ArgumentNullException

Le listItem est une référence Null (Rien dans Visual Basic), qui n'est pas valide.

Remarques

Utilisez cette méthode pour instancier une instance de PageLayout qui encapsule un objet SPListItem que vous avez déjà extrait. Le SPListItem doit être un élément dans la galerie de pages maîtres de la collection de sites.

Le listItem doit être une instance de SPListItem et ne peut pas être une référence Null (Rien dans Visual Basic).

Exemples

Avant de compiler et d'exécuter cet exemple, vérifiez que l'objet SPListItem est un élément de liste pour une mise en page qui se trouve dans la galerie de pages maîtres sur le site Web de niveau supérieur.

Cet exemple suppose que la galerie de page maître qui contient l'objet SPListItem nécessite l'approbation de contenu.

using PageLayout = Microsoft.SharePoint.Publishing.PageLayout;
using SPListItem = Microsoft.SharePoint.SPListItem;
using SPFile = Microsoft.SharePoint.SPFile;

namespace Microsoft.SDK.SharePointServer.Samples
{
    public static class PageLayoutCodeSamples
    {
        // This method sets some properties on a PageLayout object,
        // saves the new values, and publishes the PageLayout.
        public static void SetPageLayoutPropertiesAndApprove(SPListItem layoutListItem)
        {
            // Replace these variable values and input
            // parameters with your own values.
            // New PageLayout.Title value
            string newTitle = "your Title";
            // New PageLayout.Description value
            string newDescription = "your Description";
            // The comment to set when the layout is checked in,
            // published, and approved.
            string checkInComment = "your comments";
            // Validate the input parameters.
            if (null == layoutListItem)
            {
                throw new System.ArgumentNullException("layoutListItem");
            }

            // Get the PageLayout wrapper for the SPListItem
            // that is passed.
            PageLayout pageLayout = new PageLayout(layoutListItem);

            // Check out the PageLayout if it is not checked out yet.
            if (pageLayout.ListItem.File.CheckOutStatus == SPFile.SPCheckOutStatus.None)
            {
                pageLayout.ListItem.File.CheckOut();
            }

            // Set and save some properties on the PageLayout object.
            pageLayout.Title = newTitle;
            pageLayout.Description = newDescription;
            pageLayout.Update();

            // Publish the PageLayout and approve it so that the
            // updated values are available on the published Web site.
            pageLayout.ListItem.File.CheckIn(checkInComment);
            SPFile layoutFile = pageLayout.ListItem.File;
            layoutFile.Publish(checkInComment);
            layoutFile.Approve(checkInComment);

        }
    }
}
Imports PageLayout = Microsoft.SharePoint.Publishing.PageLayout
Imports SPListItem = Microsoft.SharePoint.SPListItem
Imports SPFile = Microsoft.SharePoint.SPFile

Namespace Microsoft.SDK.SharePointServer.Samples
    Public NotInheritable Class PageLayoutCodeSamples
        ' This method sets some properties on a PageLayout object,
        ' saves the new values, and publishes the PageLayout.
        Private Sub New()
        End Sub
        Public Shared Sub SetPageLayoutPropertiesAndApprove(ByVal layoutListItem As SPListItem)
            ' Replace these variable values and input
            ' parameters with your own values.
            ' New PageLayout.Title value
            Dim newTitle As String = "your Title"
            ' New PageLayout.Description value
            Dim newDescription As String = "your Description"
            ' The comment to set when the layout is checked in,
            ' published, and approved.
            Dim checkInComment As String = "your comments"
            ' Validate the input parameters.
            If Nothing Is layoutListItem Then
                Throw New System.ArgumentNullException("layoutListItem")
            End If

            ' Get the PageLayout wrapper for the SPListItem
            ' that is passed.
            Dim pageLayout As New PageLayout(layoutListItem)

            ' Check out the PageLayout if it is not checked out yet.
            If pageLayout.ListItem.File.CheckOutStatus = SPFile.SPCheckOutStatus.None Then
                pageLayout.ListItem.File.CheckOut()
            End If

            ' Set and save some properties on the PageLayout object.
            pageLayout.Title = newTitle
            pageLayout.Description = newDescription
            pageLayout.Update()

            ' Publish the PageLayout and approve it so that the
            ' updated values are available on the published Web site.
            pageLayout.ListItem.File.CheckIn(checkInComment)
            Dim layoutFile As SPFile = pageLayout.ListItem.File
            layoutFile.Publish(checkInComment)
            layoutFile.Approve(checkInComment)

        End Sub
    End Class
End Namespace

Voir aussi

Référence

PageLayout classe

PageLayout - Membres

Microsoft.SharePoint.Publishing - Espace de noms