Export (0) Print
Expand All

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)

public PublishingPageCollection GetPublishingPages()

ExceptionCondition
[Microsoft.SharePoint.Publishing.InvalidPublishingWebException]

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

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.

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);          
        }
    }
}

Community Additions

ADD
Show:
© 2014 Microsoft