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.

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!

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

  • 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 Sep 19 '13 at 8:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.