How to Create a Modern Site Programmatically in SharePoint Office 365 using Patterns and Practice (OfficeDevPNP)

Sathish Nadarajan
Solution Architect
May 2, 2018
Rate this article
[Total: 0    Average: 0/5]

The article explains about how to create a modern site in SharePoint Office 365 Programmatically. This will be helpful, during the provisioning of the sites. There are a lot of difference between the modern and the classic sites. Already some time back, we have seen how to create the Classic Sites programmatically HERE. But, the modern sites cannot be created in that way. It requires a minor change and we can have a look on it in this article.

Usually, when we create a site by SharePoint Admin Portal, we cannot see the templates of the Modern sites.



We cannot see the Modern site templates (Modern Team Site and Communication Site here). To do that, we need to go the below screen. https://<<TenantName>>


This is a manual process and these sites will also be NOT listed on the site collections list.



We can see in the upcoming articles to get the list of Modern sites available in the tenant and how to delete them. As of now, let us see how to create the modern sites using C# CSOM PNP.

 public static async Task CreateCommunicationSite(string Password, string siteTitle)
             string UserName = "sathish@*****";
             using (var clientContext = new ClientContext("https://********"))
                 SecureString passWord = new SecureString();
                 foreach (char c in Password.ToCharArray()) passWord.AppendChar(c);
                 clientContext.Credentials = new SharePointOnlineCredentials(UserName, passWord);
                 var commResults = await clientContext.CreateSiteAsync(new OfficeDevPnP.Core.Sites.CommunicationSiteCollectionCreationInformation()
                     Url = "https://*****" + siteTitle,
                     SiteDesign = OfficeDevPnP.Core.Sites.CommunicationSiteDesign.Topic,
                     Title = siteTitle,
                     Lcid = 1033


The above method will be called from the main method as below.

 SiteCollections.CreateCommunicationSite(password, "SiteTitle").Wait();

In the same manner, the Modern Team site can also be created.

This will be useful during the Provisioning exercise.

Happy Coding,

Sathish Nadarajan.

Author Info

Sathish Nadarajan
Solution Architect
Rate this article
[Total: 0    Average: 0/5]
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 13+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business more

Leave a comment