1

I want to create publishing page in pages library via JSOM (ecma script) or REST api. Is there any way we can create in SharePoint 2010? Please let me know if anyone has any idea?

Thanks, Rajeev K

0

Here is my JSOM:

factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
    context.set_webRequestExecutorFactory(factory);
    appContextSite = new SP.AppContextSite(context, hostweburl);
    oWeb = appContextSite.get_web();
    oList = oWeb.get_lists().getByTitle('pages');

    fileCreateInfo = new SP.FileCreationInformation();
    fileCreateInfo.set_url("myPage.aspx");
    fileCreateInfo.set_content(new SP.Base64EncodedByteArray());
    fileContent = "<%@ Page Inherits=\"Microsoft.SharePoint.Publishing.TemplateRedirectionPage,Microsoft.SharePoint.Publishing,Version=15.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c\" %> <%@ Reference VirtualPath=\"~TemplatePageUrl\" %> <%@ Reference VirtualPath=\"~masterurl/custom.master\" %>";

    for (var i = 0; i < fileContent.length; i++) {
        fileCreateInfo.get_content().append(fileContent.charCodeAt(i));
    }

    newFile = oList.get_rootFolder().get_files().add(fileCreateInfo);

    context.load(newFile);
    context.executeQueryAsync(function () {
        alert('yo');
    }, function (sender, args) {
        alert(args.get_message() + '\n' + args.get_stackTrace());
    }); 

By using above JSOM code, you can create a Publishing page under PAGES library in SharePoint 2013.

NOTE:- ECMA (JSOM) script will not work to create a document in SharePoint 2010 library.

If you need more help than please let me know.

  • Hello Hardik, Thanks for quick response. But it looks like its for SharePoint 2013 ..? I want it for 2010 it gives error for sp.FileCreationINformation in 2010. Do you have any idea how to do this especially in 2010 ? – Rajeev K Apr 8 '16 at 5:44
  • Opps. You are right. they introduced SP.FileCreationInformation() in SharePoint 2013. You must have to use WEB SERVICE instead of JSOM. – Hardik Apr 8 '16 at 5:54
  • yes, looks like that.. do you have any inputs for that? If yes, please do share, will be helpful for me..:) – Rajeev K Apr 8 '16 at 5:58
  • please refer this post stackoverflow.com/questions/6199990/… – Hardik Apr 8 '16 at 6:13
  • yes, saw that. but I want it for ecma script or may be reset api – Rajeev K Apr 8 '16 at 6:19

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.