次のコードを使用して、コンテンツ タイプに基づいて既にプロビジョニングされていると見なされるページ レイアウトに基づいて発行ページを作成します。コードは、機能の FeatureActivated イベント ハンドラーで実行されます。
using (SPWeb ParentWeb = properties.Feature.Parent as SPWeb)
{
PublishingWeb webpublish = PublishingWeb.GetPublishingWeb(ParentWeb);
//retrieve the layout associated with our custom content type
PageLayout[] layouts = webpublish.GetAvailablePageLayouts(new SPContentTypeId(MyContentTypeID));
//first layout considered, as this is the one created by this feature
PageLayout MyPageLayout = layouts[0];
PublishingPageCollection PublishingPages = webpublish.GetPublishingPages();
PublishingPage newPage = PublishingPages.Add("NewPublishingPageName.aspx", MyPageLayout);
newPage.Title = "My first publishing page";
newPage.ListItem.Update();
//check-in and republish the page
SPFile listItemFile = newPage.ListItem.File;
//check that the file is not checked out - if it is, check it in.
if (listItemFile.CheckOutStatus != SPFile.SPCheckOutStatus.None)
{
listItemFile.CheckIn("Initial default content added.");
}
listItemFile.Publish("");
listItemFile.Approve("");
}