Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

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!

share|improve this answer

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.

2  
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
1  
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. –  Waqas Sarwar MCSE May 10 at 20:32

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");
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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