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 sample creates a new PublishingPage in a PublishingWeb.

Before compiling and running this sample, 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.

[c#]

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 )
        {
            // TODO: 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);          
        }
    }
}

See Also

Reference

PublishingWeb Class

PublishingWeb Members

GetPublishingPages Overload

Microsoft.SharePoint.Publishing Namespace