Forum Discussion

null null's avatar
null null
Iron Contributor
Nov 23, 2018

create a Modern Team Site using Template pro grammatically using CSOM or PnP

I am planning to create a Modern Team Site using Template pro grammatically using CSOM or PnP

 

could you please direct me to a link where 

1) to create a template of a modern team site - techniques

2) sample code for creating the site programmatically

  • Hi there,

     

    To grab the template of a modern team site, you can use PnP PowerShell (or C#) Get-PnPProvisioningTemplate.

     

    How to create the modern team site programmatically will depend on whether you want it to be group connected or not. For a non group connected team site, simply call your normal CSOM or PnP method for creating a site and pass in Template STS#3.

     

    For a group connected team site, you need to create an Office 365 group and pass in a "mailNickname" parameter which will determine the name of the team site.

     

    You can do this in a number of ways. With REST via a POST request to the Graph endpoint: https://graph.microsoft.com/v1.0/groups

     

    The following would create an Office 365 group and an associated "modern" team site with a URL of https://[tenant].sharepoint.com/sites/mymodernteamsite

    POST https://graph.microsoft.com/v1.0/groups
    Content-type: application/json
    Content-length: 200
    {
    "description": "description",
    "displayName": "My modern team site",
    "groupTypes": [
    "Unified"
    ],
    "mailEnabled": true,
    "mailNickname": "mymodernteamsite",
    "securityEnabled": false
    }

     

    You can also achieve this via PowerShell as explained in the following article

     

    https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/modern-experience-customizations-provisioning-sites

     

    Note that you can't create group connected team sites using PowerShell with App-Only permissions yet, however, you should be able to call the Graph endpoint.

    • null null's avatar
      null null
      Iron Contributor

      Is there a way to use CSOM or PnP method for creating a site and pass in Template STS#3 using C#?

       

      As i want to create the site collection programmatically using templates based on Modern Team Sites without group creation.

       

      Thanks