EnjoySharePoint YouTube Channel

Create subsite in SharePoint 2013/2016 programmatically

Create sub site using SharePoint 2016 server object model and SharePoint 2016 client object model

This SharePoint tutorial explains, how to create a subsite programmatically using the server object model and client object model in SharePoint 2013/2016.

Get Office 365 Enterprise E3 Or Business Premium Subscription & Try out all the features

I have used a windows application to create subsites in SharePoint 2016. But the same code will work for SharePoint 2013.

Create subsite in sharepoint programmatically using server object model

Below is the code to create SharePoint 2016 server object model.

using (SPSite site = new SPSite(“http://mypc:29024/sites/SPTraining/”))
{
using (SPWeb newWeb = site.OpenWeb())
{
newWeb.AllowUnsafeUpdates = true;
SPWebCollection subsites = newWeb.Webs;
SPWeb newSubWeb = subsites.Add(“MySiteFromServerObjectModel”, “My Site from Server Object Model”, “This is a site from server object model.”, 1033, “STS#0”, true, false);
newWeb.Update();
}
}

Read 15+ SharePoint server object model examples

Create subsite in SharePoint programmatically using csom (client side object model)

Below is the csom code to create a subsite programmatically using csom in SharePoint 2013/2016.

Read: SharePoint client object model tutorial

using (ClientContext ctx = new ClientContext(“http://mypc:29024/sites/SPTraining/”))
{
WebCreationInformation websitecreationinfo = new WebCreationInformation();
websitecreationinfo.Url = “MySiteFromClientObjectModel”;
websitecreationinfo.Title = “My Site from Client Object Model”;
websitecreationinfo.Description = “This is a site from client object model.”;
websitecreationinfo.UseSamePermissionsAsParentSite = true;
websitecreationinfo.WebTemplate = “STS#0”;
websitecreationinfo.Language = 1033;
Web w = ctx.Site.RootWeb.Webs.Add(websitecreationinfo);
ctx.ExecuteQuery();
}

Create sub site using SharePoint 2016 server object model and SharePoint 2016 client object model
Create sub site using SharePoint 2016 server object model and SharePoint 2016 client object model

Hope this will be helpful to create subsite programmatically using SharePoint 2016/2013 server object model or client object model.

Check out Best Alternative to InfoPath -> Try Now
You May Also like the Following SharePoint Tutorials:

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →