If you like to create pages in site through code then you have to set the page layout for the page. Below is the simple code which does that works well.
private static void SetPageLyoutToPublishibPage()Any issues, please post it here.
{
using (SPSite site = new SPSite("http://SP2010Site"))
{
using (SPWeb web = site.OpenWeb())
{
PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
PageLayout pageLayout = null;
foreach (PageLayout p in publishingWeb.GetAvailablePageLayouts())
if (p.Name.Equals("BlankWebPartPage.aspx", StringComparison.InvariantCultureIgnoreCase))
{
pageLayout = p;
break;
}
PublishingPage page = publishingWeb.GetPublishingPage(web.ServerRelativeUrl + "/Pages/Default.aspx");
page.CheckOut();
page.Layout = pageLayout;
page.Update();
page.CheckIn("");
}
}
}
0 komentar:
Post a Comment