Share via


PublishingWeb.GetPublishingPages method

Gets a collection of PublishingPage objects contained in this PublishingWeb object.

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

Syntax

'Declaration
Public Function GetPublishingPages As PublishingPageCollection
'Usage
Dim instance As PublishingWeb
Dim returnValue As PublishingPageCollection

returnValue = instance.GetPublishingPages()
public PublishingPageCollection GetPublishingPages()

Return value

Type: Microsoft.SharePoint.Publishing.PublishingPageCollection
A PublishingPageCollection collection containing PublishingPage objects in this PublishingWeb object.

Exceptions

Exception Condition
[Microsoft.SharePoint.Publishing.InvalidPublishingWebException]

The site is not valid. The Pages document library is missing.

Remarks

This method gets all PublishingPage objects for this PublishingWeb object. For a large collection, you can use data paging with the other GetPublishingPage() method(s) to retrieve this collection in smaller subsets.

To apply sorting or filtering, use a [M:Microsoft.SharePoint.Publishing.PublishingWeb.GetPublishingPages(Microsoft.SharePoint.SPQuery] method that takes SPQuery, String, or UInt32 to create a Collaborative Application Markup Language (CAML) query that specifies sorting and collection membership requirements.

Examples

This example creates a new PublishingPage in a PublishingWeb.

Before compiling and running this example, verify that an SPWeb that is a publishing Web exists and is passed in as the Web parameter. The PageLayout to use for creating the page must also be passed in.

using SPWeb = Microsoft.SharePoint.SPWeb;
using PublishingWeb = Microsoft.SharePoint.Publishing.PublishingWeb;
using PageLayout = Microsoft.SharePoint.Publishing.PageLayout;
using PublishingPageCollection = Microsoft.SharePoint.Publishing.PublishingPageCollection;
using PublishingPage = Microsoft.SharePoint.Publishing.PublishingPage;

namespace Microsoft.SDK.SharePointServer.Samples
{
    public static class PublishingPageCollectionCodeSamples
    {
        
       
        public static void CreateNewPage( SPWeb web, PageLayout pageLayout )
        {
// Replace these variable values with your own values.
string newPageName = "Contoso.aspx";    // the URL name of the new page
string checkInComment = "Your check in comments";  // the comment to set when the page is checked in

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

// 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");
}
           
// Create the new page in the PublishingWeb.
PublishingPageCollection pages = publishingWeb.GetPublishingPages();
PublishingPage newPage = pages.Add(newPageName, pageLayout);

// Check in the new page so that others can work on it.
newPage.CheckIn(checkInComment);          
        }
    }
}
Imports SPWeb = Microsoft.SharePoint.SPWeb
Imports PublishingWeb = Microsoft.SharePoint.Publishing.PublishingWeb
Imports PageLayout = Microsoft.SharePoint.Publishing.PageLayout
Imports PublishingPageCollection = Microsoft.SharePoint.Publishing.PublishingPageCollection
Imports PublishingPage = Microsoft.SharePoint.Publishing.PublishingPage

Namespace Microsoft.SDK.SharePointServer.Samples
    Public NotInheritable Class PublishingPageCollectionCodeSamples


        Private Sub New()
        End Sub
        Public Shared Sub CreateNewPage(ByVal web As SPWeb, ByVal pageLayout As PageLayout)
' Replace these variable values with your own values.
Dim newPageName As String = "Contoso.aspx" ' the URL name of the new page
Dim checkInComment As String = "Your check in comments" ' the comment to set when the page is checked in

' Validate the input parameters.
If Nothing Is web Then
    Throw New System.ArgumentNullException("web")
End If
If Nothing Is pageLayout Then
    Throw New System.ArgumentNullException("pageLayout")
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

' Create the new page in the PublishingWeb.
Dim pages As PublishingPageCollection = publishingWeb.GetPublishingPages()
Dim newPage As PublishingPage = pages.Add(newPageName, pageLayout)

' Check in the new page so that others can work on it.
newPage.CheckIn(checkInComment)
        End Sub
    End Class
End Namespace

See also

Reference

PublishingWeb class

PublishingWeb members

GetPublishingPages overload

Microsoft.SharePoint.Publishing namespace