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

In this post, we will discuss how to create a subsite using SharePoint 2016 server object model and 2016 client object model. In this example, I have used a windows application to create subsites in SharePoint 2016.

SharePoint 2016 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();

}

}

SharePoint 2016 Client Object Model:

Below is the code SharePoint 2016 Client object model:

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.

Check out Best Alternative to InfoPath -> Try Now

You May Also like the Following SharePoint Online 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 →