Posted by: reuben | January 25, 2010

Create a Team Site Programmatically (using a Site Template)

You can use top-level Web site and subsites to divide site content into distinct, separately manageable sites. Top-level Web sites can have multiple subsites, and subsites can also have multiple subsites, down as many levels as your users need. The entire structure of a top-level Web site and all of its subsites is called a Web site collection. The following diagram shows this hierarchy of sites and subsites. 

However, create a team site programmatically can be a challenging process. Sure, if you’re trying to spawn a website with no persmissions, user groups, etc then creating a team site is a trivial process. Creating custom permissions, custom look and feel, custom user groups, assigning custom permissions to these user groups, can be a tedious process. 

In this post, I’ll try to cover the following: 

  1. Create a Team Site (Under a specific root site) using a “Site Template
  2. Create Custom Membership Groups
  3. Add Users to these Membership Groups
  4. Assign Site Specific Permissions to these Groups.
  5. Customize the look and feel of specific web parts on the new site.

Note: Please keep in mind, the methodology used for creating these sites, is just one of the many approaches that can be adopted to achieve this goal. If you have a better way of doing the same, please leave a link to your blog in the comments section below. This code was hashed out in a couple of days when I was trying to meet a really tight deadline – it can be refactored and further improved upon. 


This blog turned out to be too long, I’ve posted the code to this post instead. CreateTeam.cs



  1. Hi,

    I noticed you posted an error on a site in regards to OCS and SharePoint 2010 with the following error.

    Unable to cast object of type ‘System.Security.Principal.WindowsIdentity’ to type ‘Microsoft.IdentityModel.Claims.ClaimsIdentity’

    I take it you received that error because you used a web app as claims based authenticaiton.

    Did you ever manage to resolve the error without having to use Classis Authentication?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


%d bloggers like this: