Create sub site programmatically in SharePoint 2010

Sometime we require creating a sub site programmatically in code. Here is the simple way you can create a sub site programmatically.

(SPSite site = new SPSite(http://siteCollectionUrl))

  { using (SPWeb web = site.OpenWeb())

        {try
            { web.AllowUnsafeUpdates = true;
               //Create new web site
               SPWeb newWeb = site.AllWebs.Add("Site url", " Site name", "Site description", 1033, {Name of the Site Template}, true, false); 
               newWeb.Update();
            }
            catch (Exception)  { }
            finally { web.AllowUnsafeUpdates = false; } 
             } }

 

E.g. Use “STS#0” for Team site or “BLOG#0” for Blog site.

Available site templates

Site Template Names

 

Team Site

 

STS#0

Blank Site

STS#1

Document Workspace

STS#2

Blog

BLOG#0

Group Work Site

SGS#0

Visio Process Repository

VISPRUS#0

Basic Meeting Workspace

MPS#0

Blank Meeting Workspace

MPS#1

Decision Meeting Workspace

MPS#2

Social Meeting Workspace

MPS#3

Multipage Meeting Workspace

MPS#4

Assets Web Database

ACCSRV#1

Charitable Contributions Web Database

ACCSRV#3

Contacts Web Database

ACCSRV#41

Issues Web Database

ACCSRV#6

Projects Web Database

ACCSRV#5

Document Center

BDR#0

Records Center

OFFILE#1

Business Intelligence Center

BICenterSite#0

My Site Host

SPSMSITEHOST#0

Personalization Site

SPSMSITE#0

Enterprise Search Center

SRCHCEN#0

Basic Search Center

SRCHCENTERLITE#0

FAST Search Center

SRCHCENTERFAST#0

Enterprise Wiki

ENTERWIKI#0

Publishing Portal

BLANKINTERNETCONTAINER#0

Publishing Site

CMSPUBLISHING#0

Publishing Site With Workflow

BLANKINTERNET#2

More Blogs

Contact us

To begin your digital transformation, get in touch.

We’re pleased to address any inquiries you might have and assist you in selecting the service that best suits your requirements.

Your benefits:
Speak To Us