Monday, July 21, 2014

Create Publishing page using Client Object Model

   // 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");

No comments:

Post a Comment

How to launch a document by clicking a link to the file?

Word: <a href='ms-word:ofe|u|path/to/web/word/document.docx'>Link to document</a> Excel: <a href='ms-excel:o...