none
SharePoint sub site creation process RRS feed

  • Question

  • Hello,

    I have to create my own site creation page just like newspweb.aspx. Can anyone help me out on this.

    Any help would be appreciable

    Thanks,

    Kunal

    Thursday, December 22, 2016 11:34 AM

All replies

  • Hi,

    On any of the Site Pages add the required text boxes and button to get the user input parameters and click of the button event write the below code snippet

    var createSubSite = function(templateName) {
            var webCreationInfo = new SP.WebCreationInformation();
             webCreationInfo.set_title(dataForSiteCreate[i].clientInfo.ClientName);
            webCreationInfo.set_description(dataForSiteCreate[i].clientInfo.ClientDescription);
            webCreationInfo.set_language(1033);            
            webCreationInfo.set_url(hostname);
            webCreationInfo.set_useSamePermissionsAsParentSite(true);
            webCreationInfo.set_webTemplate(templateName);
    
            var clientContext = SP.ClientContext.get_current();
    
            var newWeb = clientContext.get_web().get_webs().add(webCreationInfo);
    
            clientContext.load(newWeb);
            clientContext.executeQueryAsync(function() {
                console.log("Done");
                }, function(sender,args) { 
                console.log("failed. Message:" + args.get_message());
            });     
    }
    
    var getTemplateName = function(templateName) {
        var dfd = new $.Deferred(); 
        var clientContext = SP.ClientContext.get_current();
        var templates = clientContext.get_web().getAvailableWebTemplates(1033, false);
        clientContext.load(templates);
    
        clientContext.executeQueryAsync(function() {
            var templateGuidName;
    
            for (var template in templates.get_data()) {
                    if (templates.itemAt(template).get_title() === templateName) {
                        templateGuidName = templates.itemAt(template).get_name();
                        break;
                    }
                }   
            dfd.resolve(templateGuidName);
    
         }, function() { dfd.reject(); });
    
        return dfd.promise();
    
    }
    
    SP.SOD.executeFunc("sp.js", "SP.ClientContext", function () {
        getTemplateName("TitleOfYourTemplateHere").done(function(template) {
            createSubSite(template);    
        }); 
    });


    Murugesa Pandian | MCPD | MCTS | SharePoint 2010 |

    Thursday, December 22, 2016 1:40 PM
  • Hi,

    Is any update for your issue?

    Best Regards,

    Lee



    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, January 3, 2017 6:38 AM