1

I am using SharePoint 2013. Is there any way I can programmatically create a page using ONLY th Client Object Model? Also notice that the page should be editable for further use.

    2 Answers 2

    1

    Use PublishingWeb.AddPublishingPage method to create a new PublishingPage object in the PublishingWeb from Microsoft.SharePoint.Client.Publishing namespace in SharePoint 2013 CSOM.

    Example

    public static PublishingPage CreatePublishingPage(ClientContext ctx, string pageName, string pageLayoutName) { var pubWeb = PublishingWeb.GetPublishingWeb(ctx, ctx.Web); var pageInfo = new PublishingPageInformation { Name = pageName, PageLayoutListItem = GetPageLayoutByName(ctx, pageLayoutName) }; var publishingPage = pubWeb.AddPublishingPage(pageInfo); ctx.ExecuteQuery(); return publishingPage; } public static ListItem GetPageLayoutByName(ClientContext ctx, string name) { var list = ctx.Site.GetCatalog((int)ListTemplateType.MasterPageCatalog); var qry = new CamlQuery { ViewXml = string.Format("<View><Query><Where><Eq><FieldRef Name='FileLeafRef' /><Value Type='Text'>{0}</Value></Eq></Where></Query></View>",name) }; var result = list.GetItems(qry); ctx.Load(result); ctx.ExecuteQuery(); var item = result.FirstOrDefault(); return item; } 

    Usage

    using (var ctx = new ClientContext(webUri)) { var page = CreatePublishingPage(ctx, "Welcome.aspx", "BlankWebPartPage.aspx"); } 
      0

      http://blogs.msdn.com/b/prasannabalajim/archive/2013/05/20/how-to-add-a-publishing-page-in-sharepoint-2013-using-client-object-model.aspx

      This seems to be the answer, but I haven't tested it!

      1
      • 3
        While this may theoretically answer the question, we prefer inclusion of the essential parts of the answer here, and to provide the link for reference. See answer for general guidelines.
        – SPDoctor
        CommentedSep 19, 2013 at 8:00

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.