Creating Sub Site under Parent SharePoint Site using C# or PowerShell

Hello everyone,
If you want to create a SubSite under site collection through code use following code. This will help you to create brand new SubSite under your site collection, my given code will create a "blog" site under the site collection that you created earlier.

Code:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using Microsoft.SharePoint;

using Microsoft.SharePoint.Administration;


namespace CreateSubSite

{

    class Program

    {

        public const string siteUrl = "http://myserver:5263/sites/Training";  //url_Of_your_WebApp


        static void Main(string[] args)

        {

            SPSite site = new SPSite(siteUrl);


            // Create new subsite of type Blog   here-> 1033=us-eng  site type=BlOG#0

            SPWeb web = site.AllWebs.Add

                (

                    "BlogSiteUrl", 

                    "Blog Site", 

                    "Some Blog relevant information", 

                    1033, 

                    "BLOG#0", 

                    false, 

                    false

                );


            Console.WriteLine("Blog site has been created.");

            Console.ReadKey();

        }

    }

}

Output:

 

Two Ways to create subsite:

  • Go to site content select new Subsite and fill all the details click create this will create a subsite for you.
  • Use Visual Studio via C# language
  • Use PowerShell

For PowerShell --> Open SharePoint 2013 Management Shell and use following Script:

PowerShell command for creating subsite:

$template = Get-SPWebTemplate "STS#0"

New-SPWeb http://dsknomoe12:5566/subsite -Template $template

 

 Subsite created successfully.........

Subscribe my blog...........

 
 

Add comment