Export (0) Print
Expand All

PublishingPage.ContentType property

Gets the content that is available to this PublishingPage object.

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

'Declaration
Public ReadOnly Property ContentType As SPContentType
	Get
'Usage
Dim instance As PublishingPage
Dim value As SPContentType

value = instance.ContentType

Property value

Type: Microsoft.SharePoint.SPContentType
The ContentType property gets the SPContentType for this PublishingPage.

The Layout property that provides rendering information to the PublishingPage matches the ContentTypeproperty(). The PageLayout object supports rendering the pieces of content that are associated with the SPContentType.

The ContentType property value is initialized when you create a PublishingPage; this value is based on the AssociatedContentType and cannot be modified.

The user must have View permissions on the PublishingPage to retrieve it and to return its property values.

This example replaces the PageLayout object for all PublishingPage objects in a Web to a new PageLayout that renders the same type of content.

Before compiling and running this example, verify that the oldPageLayout and newPageLayout render the same content. They should use the same AssociatedContentType value.

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

Community Additions

ADD
Show:
© 2014 Microsoft