.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Melody Anderson

Home >> Articles >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Create Site automatically when a List item is added

Posted By:Jean Paul       Posted Date: November 30, 2014    Points: 200    Category: SharePoint    URL: http://www.dotnetspark.com  

In this article we will explore a real world scenario of project site creation through list item adding event. The source code is attached with the article.


In your company there are multiple projects going on. For each project, they require a separate site. The site creation has to be done through a list item creation.

A list named Projects exists in the root SharePoint site. A user can add a new item in the list along with the Project information.

1. Project Name

2. Project Description

3. Start Date

4. End Date

5. Team Members

Step 1: Create Projects list

Please go ahead & create a new list name Projects. Add the columns as displayed below.

Ensure that the Team Members column is of type User or Group & it allows multiple selections.

Step 2: Create SharePoint Project

Now we can start with our Event Handler Project. Open Visual Studio 2012 & create an empty SharePoint Project.

If you do not have Visual Studio 2012, you need to install it first. After that, install the Office Tools for Visual Studio 2012, it contains the SharePoint project templates.

In the next page, choose the Farm Solution option.

Now, right click on the project & add an Event Receiver.

Choose the custom list option & "item was added" event as given below:

In the item added event, place the following Site Creation code.


public override void ItemAdded(SPItemEventProperties properties)

    if (properties.List.Title == "Projects")
        // Get Properties
        string name = properties.ListItem["Title"].ToString();
        string description = properties.ListItem["Description"].ToString();
        DateTime startDate = (DateTime)properties.ListItem["Start Date"];
        DateTime endDate = (DateTime)properties.ListItem["End Date"];

        // Create sub site
        SPWeb web = properties.Site.AllWebs.Add(name.Replace(" ", string.Empty), name, 
            description, 0, SPWebTemplate.WebTemplateSTS, false, false);

Step 3: Execute Project

Now execute the project using F5 key& while debugging active, create a new project item inside Projects list.

You can see that a new sub site is created based on the input information.

Step 4: View sub site

Use the Site Contents link to view the sub sites.

Scrolling down to the bottom of the page, you can see our new site named Supercast.

On clicking the sub site, it opens as shown below:

In this example, we have stopped after creation of sub sites. In the real world projects we need to:

1. Create an Internal List with all project information

2. In the add event, create a web part display project information from list & add to home page

3. In the original Projects list, create a new property named URL & set that to the newly created site

4. In the new site, Owners & Members permission groups can be automatically created

5. Create common project library, list, meeting, discussion lists in the site.

In appropriate sense, the custom solution can include a custom site template with all pre-defined lists & libraries.




In this article we have explored a real world scenario of project site creation through list item adding event. The source code is attached with the article.

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend