Partager via


PublishingPage.GetPublishingPage - Méthode

Obtient une instance de l'objet PublishingPage qui encapsule l'objet donné SPListItem .

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

Syntaxe

'Déclaration
Public Shared Function GetPublishingPage ( _
    sourceListItem As SPListItem _
) As PublishingPage
'Utilisation
Dim sourceListItem As SPListItem
Dim returnValue As PublishingPage

returnValue = PublishingPage.GetPublishingPage(sourceListItem)
public static PublishingPage GetPublishingPage(
    SPListItem sourceListItem
)

Paramètres

Valeur renvoyée

Type : Microsoft.SharePoint.Publishing.PublishingPage
Une instance de PublishingPage qui encapsule le donné SPListItem.

Exceptions

Exception Condition
[System.ArgumentException]

Non valide SPListItem. Le SPListItem fourni n'est pas compatible avec une PublishingPage.

[System.ArgumentNullException]

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

Remarques

Il s'agit d'une méthode statique. Elle permet d'obtenir une instance de l'objet PublishingPage qui encapsule un SPListItem que vous avez déjà extrait. Vous pouvez également utiliser la méthode PublishingWeb.GetPublishingPages pour obtenir une instance de PublishingPage .

Le sourceListItem doit être une instance non null SPListItem .

Exemples

Cet exemple montre comment définit certaines propriétés sur un objet PublishingPage , enregistre les nouvelles valeurs et publie le PublishingPage.

Avant de compiler et exécuter cet exemple, vérifiez que ce SPLIstItem est un élément de liste dans la bibliothèque de documents Pages d'un PublishingWeb.

Cet exemple suppose que la bibliothèque de documents qui contient le SPListItem nécessite l'approbation du contenu.

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 SetPagePropertiesAndApprove(SPListItem listItem, SPUser pageContact)
        {
            // Replace these variable values and input parameters with your own values.
            //
            // New PublishingPage.Title value
            string newTitle = "your Title";
            //
            // New PublishingPage.Description value
            string newDescription = "your Description";
            //
            // The comment to set when the page is checked in, published, and approved.
            string checkInComment = "Your comments";

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

            // Get the PublishingPage wrapper for the SPListItem that was passed in.
            //
            PublishingPage publishingPage = null;
            if (PublishingPage.IsPublishingPage(listItem))
            {
                publishingPage = PublishingPage.GetPublishingPage(listItem);
            }
            else
            {
                throw new System.ArgumentException("This SPListItem is not a PublishingPage", "listItem");
            }

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

            
            // Set and save some properties on the PublishingPage.
            //
            publishingPage.Title = newTitle;
            publishingPage.Description = newDescription;
            publishingPage.Contact = pageContact;
            publishingPage.Update();

            
            // Publish the page, and approve it if required, so that the updated 
            // values are visible on the published Web site.
            //
            publishingPage.CheckIn(checkInComment);
            SPFile pageFile = publishingPage.ListItem.File;
            pageFile.Publish(checkInComment);
            pageFile.Approve(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 SetPagePropertiesAndApprove(ByVal listItem As SPListItem, ByVal pageContact As SPUser)
            ' Replace these variable values and input parameters with your own values.
            '
            ' New PublishingPage.Title value
            Dim newTitle As String = "your Title"
            '
            ' New PublishingPage.Description value
            Dim newDescription As String = "your Description"
            '
            ' 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 listItem Then
                Throw New System.ArgumentNullException("listItem")
            End If
            If Nothing Is pageContact Then
                Throw New System.ArgumentNullException("pageContact")
            End If

            ' Get the PublishingPage wrapper for the SPListItem that was passed in.
            '
            Dim publishingPage As PublishingPage = Nothing
            If PublishingPage.IsPublishingPage(listItem) Then
                publishingPage = PublishingPage.GetPublishingPage(listItem)
            Else
                Throw New System.ArgumentException("This SPListItem is not a PublishingPage", "listItem")
            End If


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


            ' Set and save some properties on the PublishingPage.
            '
            publishingPage.Title = newTitle
            publishingPage.Description = newDescription
            publishingPage.Contact = pageContact
            publishingPage.Update()


            ' Publish the page, and approve it if required, so that the updated 
            ' values are visible on the published Web site.
            '
            publishingPage.CheckIn(checkInComment)
            Dim pageFile As SPFile = publishingPage.ListItem.File
            pageFile.Publish(checkInComment)
            pageFile.Approve(checkInComment)
        End Sub
    End Class
End Namespace

Voir aussi

Référence

PublishingPage classe

PublishingPage - Membres

Microsoft.SharePoint.Publishing - Espace de noms