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

%3CLINGO-SUB%20id%3D%22lingo-sub-290608%22%20slang%3D%22en-US%22%3Ecreate%20a%20Modern%20Team%20Site%20using%20Template%20pro%20grammatically%20using%20CSOM%20or%20PnP%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-290608%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20planning%20to%20create%20a%20Modern%20Team%20Site%20using%20Template%20pro%20grammatically%20using%20CSOM%20or%20PnP%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ecould%20you%20please%20direct%20me%20to%20a%20link%20where%26nbsp%3B%3C%2FP%3E%3CP%3E1)%20to%20create%20a%20template%20of%20a%20modern%20team%20site%20-%20techniques%3C%2FP%3E%3CP%3E2)%20sample%20code%20for%20creating%20the%20site%20programmatically%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-290608%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPnP%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-300870%22%20slang%3D%22en-US%22%3ERe%3A%20create%20a%20Modern%20Team%20Site%20using%20Template%20pro%20grammatically%20using%20CSOM%20or%20PnP%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-300870%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20getting%20the%20below%20error%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-Sites-Core%2Fissues%2F1450%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-Sites-Core%2Fissues%2F1450%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20the%20PnP%20Templating%20mature%20enough%20to%20be%20embraced%20in%20the%20industry%20or%20should%20we%20go%20for%20Site%20Script%20-%20Site%20design%20approach.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20not%20sure%20if%20Microsoft%20would%20support%20PnP%20or%20Site%20Script%2FDesign%20as%20it%20appears%20PnP%20has%20not%20matured%20to%20handle%20Modern%20Team%20site%20with%20themes%20o%20be%20applied.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECould%20you%20please%20shed%20some%20light%20on%20this.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-292732%22%20slang%3D%22en-US%22%3ERe%3A%20create%20a%20Modern%20Team%20Site%20using%20Template%20pro%20grammatically%20using%20CSOM%20or%20PnP%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-292732%22%20slang%3D%22en-US%22%3E%3CP%3EUsing%20the%20PnP%20Core%20library%2C%20you%20can%26nbsp%3Buse%20the%20tenant%20extension%20method%2C%20%22%3CSPAN%3ECreateSiteCollection%22%2C%20which%20accepts%20a%20SiteEntity%20object%20as%20a%20parameter.%20That%26nbsp%3BSiteEntity%26nbsp%3Bobject%20defines%20(among%20other%20things)%20the%20template%20(STS%233%20in%20this%20case).%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-Sites-Core%2Fblob%2Fmaster%2FCore%2FOfficeDevPnP.Core%2FExtensions%2FTenantExtensions.cs%23L53%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-Sites-Core%2Fblob%2Fmaster%2FCore%2FOfficeDevPnP.Core%2FExtensions%2FTenantExtensions.cs%23L53%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20use%20the%20PnP%20method.%20Inside%20that%20method%20you'll%20see%20the%20CSOM%20method%20it's%20wrapped%20around%20(tenant.CreateSite())%20which%20takes%20a%26nbsp%3B%3CSPAN%3ESiteCreationProperties%20object%20which%20defines%20the%20template.%20You%20could%20also%20use%20that%20method%20directly%20if%20you%20want%20pure%20CSOM.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-292685%22%20slang%3D%22en-US%22%3ERe%3A%20create%20a%20Modern%20Team%20Site%20using%20Template%20pro%20grammatically%20using%20CSOM%20or%20PnP%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-292685%22%20slang%3D%22en-US%22%3E%3CP%3EIs%20there%20a%20way%20to%20use%26nbsp%3B%3CSPAN%3ECSOM%20or%20PnP%20method%20for%20creating%20a%20site%20and%20pass%20in%20Template%20STS%233%20using%20C%23%3F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EAs%20i%20want%20to%20create%20the%20site%20collection%20programmatically%26nbsp%3Busing%20templates%20based%20on%20Modern%20Team%20Sites%20without%20group%20creation.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EThanks%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-292122%22%20slang%3D%22en-US%22%3ERe%3A%20create%20a%20Modern%20Team%20Site%20using%20Template%20pro%20grammatically%20using%20CSOM%20or%20PnP%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-292122%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20there%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETo%20grab%20the%20template%20of%20a%20modern%20team%20site%2C%20you%20can%20use%20PnP%20PowerShell%20(or%20C%23)%20Get-PnPProvisioningTemplate.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHow%20to%20create%20the%20modern%20team%20site%20programmatically%20will%20depend%20on%20whether%20you%20want%20it%20to%20be%20group%20connected%20or%20not.%20For%20a%20non%20group%20connected%20team%20site%2C%20simply%20call%20your%20normal%20CSOM%20or%20PnP%20method%20for%20creating%20a%20site%20and%20pass%20in%20Template%20STS%233.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20a%20group%20connected%20team%20site%2C%20you%20need%20to%20create%20an%20Office%20365%20group%20and%20pass%20in%20a%20%22%3CSPAN%3EmailNickname%3C%2FSPAN%3E%22%20parameter%20which%20will%20determine%20the%20name%20of%20the%20team%20site.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20can%20do%20this%20in%20a%20number%20of%20ways.%20With%20REST%20via%20a%20POST%20request%20to%20the%20Graph%20endpoint%3A%26nbsp%3B%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2Fgroups%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2Fgroups%3C%2FA%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EThe%20following%20would%20create%20an%20Office%20365%20group%20and%20an%20associated%20%22modern%22%20team%20site%20with%20a%20URL%20of%20https%3A%2F%2F%5Btenant%5D.sharepoint.com%2Fsites%2Fmymodernteamsite%3CBR%20%2F%3E%3CBR%20%2F%3EPOST%20%3CA%20href%3D%22https%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2Fgroups%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2Fgroups%3C%2FA%3E%3CBR%20%2F%3EContent-type%3A%20application%2Fjson%3CBR%20%2F%3EContent-length%3A%20200%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%22description%22%3A%20%22description%22%2C%3CBR%20%2F%3E%22displayName%22%3A%20%22My%20modern%20team%20site%22%2C%3CBR%20%2F%3E%22groupTypes%22%3A%20%5B%3CBR%20%2F%3E%22Unified%22%3CBR%20%2F%3E%5D%2C%3CBR%20%2F%3E%22mailEnabled%22%3A%20true%2C%3CBR%20%2F%3E%22mailNickname%22%3A%20%22mymodernteamsite%22%2C%3CBR%20%2F%3E%22securityEnabled%22%3A%20false%3CBR%20%2F%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EYou%20can%20also%20achieve%20this%20via%20PowerShell%20as%20explained%20in%20the%20following%20article%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fdev%2Fsolution-guidance%2Fmodern-experience-customizations-provisioning-sites%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fdev%2Fsolution-guidance%2Fmodern-experience-customizations-provisioning-sites%3C%2FA%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3ENote%20that%20you%20can't%20create%20group%20connected%20team%20sites%26nbsp%3Busing%20PowerShell%20with%20App-Only%20permissions%20yet%2C%20however%2C%20you%20should%20be%20able%20to%20call%20the%20Graph%20endpoint.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Regular Contributor

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

4 Replies
Highlighted

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-p...

 

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.

Highlighted

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

Highlighted

Using the PnP Core library, you can use the tenant extension method, "CreateSiteCollection", which accepts a SiteEntity object as a parameter. That SiteEntity object defines (among other things) the template (STS#3 in this case).

 

https://github.com/SharePoint/PnP-Sites-Core/blob/master/Core/OfficeDevPnP.Core/Extensions/TenantExt...

 

I would use the PnP method. Inside that method you'll see the CSOM method it's wrapped around (tenant.CreateSite()) which takes a SiteCreationProperties object which defines the template. You could also use that method directly if you want pure CSOM.

 

Highlighted

I am getting the below error

https://github.com/SharePoint/PnP-Sites-Core/issues/1450

 

Is the PnP Templating mature enough to be embraced in the industry or should we go for Site Script - Site design approach.

 

I am not sure if Microsoft would support PnP or Site Script/Design as it appears PnP has not matured to handle Modern Team site with themes o be applied.

 

Could you please shed some light on this.