Created
February 26, 2017 08:05
-
-
Save luismanez/3caac7337da86e8aeb10465598152b5f to your computer and use it in GitHub Desktop.
Adding a moder news page from CSOM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AuthenticationManager authManager = new AuthenticationManager(); | |
ClientContext context = | |
authManager.GetSharePointOnlineAuthenticatedContextTenant(url, user, password); | |
var pageName = string.Format("ModernNewsPage_{0}.aspx", DateTime.Now.ToString("yyyyMMdd_HHmmss")); | |
List pagesLibrary = context.Web.GetListByTitle("Site Pages"); | |
var pagesLibraryUrl = pagesLibrary.RootFolder.ServerRelativeUrl; | |
var newPageUrl = pagesLibraryUrl + "/" + pageName; | |
ListItem item = | |
pagesLibrary.RootFolder.Files.AddTemplateFile(newPageUrl, TemplateFileType.ClientSidePage).ListItemAllFields; | |
// Make this page a "modern news article page" | |
item["ContentTypeId"] = "0x0101009D1CB255DA76424F860D91F20E6C4118"; | |
item["Title"] = System.IO.Path.GetFileNameWithoutExtension(pageName); | |
item["ClientSideApplicationId"] = "b6917cb1-93a0-4b97-a84d-7cf49975d4ec"; | |
item["PageLayoutType"] = "Article"; | |
item["PromotedState"] = "2"; | |
item["CanvasContent1"] = "<div></div>"; | |
item["FirstPublishedDate"] = DateTime.Now; | |
item["BannerImageUrl"] = "/_layouts/15/images/sitepagethumbnail.png"; | |
item.Update(); | |
context.Load(item); | |
context.ExecuteQuery(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment