PnP core component contains the extension methods which help to achieve the SharePoint task in simple lines of code. So to know more about PnP Core component, have a look at “Introduction to PnP Core Component”.
There are two extension methods available for creating subsite,
- CreateWeb(SiteEntity subsite, boolinheritPermissions = true, boolinheritNavigation = true)
| Parameters | Description |
| subsite | Details of the Web (site) to add. Only Title, Url (as the leaf URL), Description, Template and Language are used. |
| inheritPermissions | Specifies whether the new site will inherit permissions from its parent site. |
| inheritNavigation | Specifies whether the site inherits navigation. |
- CreateWeb(string title, stringleafUrl, string description, string template, int language, boolinheritPermissions = true, boolinheritNavigation = true)
| Parameters | Description |
| title | The title of the new site. |
| leafUrl | A string that represents the URL leaf name. |
| description | The description of the new site. |
| template | The name of the site template to be used for creating the new site. |
| language | The locale ID that specifies the language of the new site. |
| inheritPermissions | Specifies whether the new site will inherit permissions from its parent site. |
| inheritNavigation | Specifies whether the site inherits navigation. |
Follow the steps below to create application with required references used for subsite creation in SharePoint.
- Create a console application.
- Add PnP core component assembly references to the application. Refer “Introduction to PnP Core Component” to add a references to the VS solution.
- Add Using Microsoft.SharePoint.Client and Using OfficeDevPnP.Core.Extensions as using statement to the top of the file.
- Add the below code snippet and change the values where ever necessary. This code sample creates a subsite called “Sample Site” with url as “samplesite” under root web of the site collection.
Code Snippet
- using System;
- usingSystem.Collections.Generic;
- usingSystem.Linq;
- usingSystem.Text;
- usingSystem.Threading.Tasks;
- usingMicrosoft.SharePoint.Client;
- usingOfficeDevPnP.Core;
- namespaceCreatSubSiteApplication
- {
- classProgram
- {
- staticvoid Main(string[] args)
- {
- stringsiteUrl = "https://mycompany.sharepoint.com";
- boolisInheritPermissions = false;
- boolisInheritNavigation = false;
- AuthenticationManagerauthManager = newAuthenticationManager();
- //Interactive Login to SharePoint site - Opens anOffice 365sign in page to authenticate the user
- var context = authManager.GetWebLoginClientContext(siteUrl);
- try
- {
- Webweb = context.Site.RootWeb.CreateWeb(
- newOfficeDevPnP.Core.Entities.SiteEntity()
- {
- Title = "Sample Site",
- Url = "samplesite",
- Description = "Site creating for testing purpose",
- Template = "STS#0",
- Lcid = 1033
- }, isInheritPermissions, isInheritNavigation);
- Console.WriteLine(web.Title + " site created successfully");
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- Console.Read();
- }
- }
- }
Output
Sample Site was created successfully.
Summary
In this article you will see how to use PnP core component for creating a subsite.

Kuppurasu NagarajPosted May 17, 2016, 10:58 AM
Nice sharing..
Debasis SahaPosted May 17, 2016, 9:48 AM
Nice one..
Shantha Kumar TPosted May 17, 2016, 6:42 AM
Thanks Bhuvanesh
Bhuvanesh MohankumarPosted May 17, 2016, 5:46 AM
Good one
Shantha Kumar TPosted May 17, 2016, 4:12 AM
Thanks to all
Ketak BhalsingPosted May 17, 2016, 1:52 AM
Great Info....
Sonu ChaudharyPosted May 16, 2016, 3:20 PM
good one...
Debasis SahaPosted May 16, 2016, 1:49 PM
Nice One..