// Get Publishing Page Layouts
List publishingLayouts = context.Site.RootWeb.Lists.GetByTitle("Master Page Gallery");
ListItemCollection allItems = publishingLayouts.GetItems(CamlQuery.CreateAllItemsQuery());
context.Load(allItems, items => items.Include(item => item.DisplayName).Where(obj => obj.DisplayName == "BlankwepartPage"));
context.ExecuteQuery();
ListItem layout = allItems.Where(x => x.DisplayName == "BlankwepartPage").FirstOrDefault();
context.Load(layout);
// Create a publishing page
PublishingPageInformation publishingPageInfo = new PublishingPageInformation();
publishingPageInfo.Name = "Newpage.aspx";
publishingPageInfo.PageLayoutListItem = layout;
PublishingPage publishingPage = web.AddPublishingPage(publishingPageInfo);
publishingPage.ListItem.File.CheckIn(string.Empty, CheckinType.MajorCheckIn);
publishingPage.ListItem.File.Publish(string.Empty);
context.Load(publishingPage);
context.Load(publishingPage.ListItem.File, obj => obj.ServerRelativeUrl);
context.ExecuteQuery();
Console.WriteLine("Newpage.aspx Created and check-in completed");
List publishingLayouts = context.Site.RootWeb.Lists.GetByTitle("Master Page Gallery");
ListItemCollection allItems = publishingLayouts.GetItems(CamlQuery.CreateAllItemsQuery());
context.Load(allItems, items => items.Include(item => item.DisplayName).Where(obj => obj.DisplayName == "BlankwepartPage"));
context.ExecuteQuery();
ListItem layout = allItems.Where(x => x.DisplayName == "BlankwepartPage").FirstOrDefault();
context.Load(layout);
// Create a publishing page
PublishingPageInformation publishingPageInfo = new PublishingPageInformation();
publishingPageInfo.Name = "Newpage.aspx";
publishingPageInfo.PageLayoutListItem = layout;
PublishingPage publishingPage = web.AddPublishingPage(publishingPageInfo);
publishingPage.ListItem.File.CheckIn(string.Empty, CheckinType.MajorCheckIn);
publishingPage.ListItem.File.Publish(string.Empty);
context.Load(publishingPage);
context.Load(publishingPage.ListItem.File, obj => obj.ServerRelativeUrl);
context.ExecuteQuery();
Console.WriteLine("Newpage.aspx Created and check-in completed");
No comments:
Post a Comment