Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

    Advertisements
  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand
  • Advertisements

Create Site Definition with List Instance

Posted by Paul on February 4, 2014


In this article I will take you through a real-world scenario.

1. You need to create a Site Definition

2. When user creates a new site from this Site Definition, a new List Instance too be created

What is the Solution?

We can have multiple solutions for this:

1. Use Feature Stapling

2. Use Event Handler

3. Use Site Definition

I would recommend the third approach as it is the shortest path.

Steps

Following are the steps involved for the solution:

1. Create SharePoint Solution Project

2. Create Site Definition

3. Create List Definition

4. Include List in Site Definition

5. Deploy

6. Test

Step 1: Create SharePoint Solution Project

Run Visual Studio 2012 & create a new SharePoint project.

image

Choose the Farm Solution option as shown below.

image

Step 2: Create Site Definition

Choose Solution > Add new item > Site Definition

image

Enter a name for the site definition.

Step 3: Create List Definition

Add a new item > List

image

Enter a name for the list instance. Choose the option custom and click the Next button of wizard.

(the custom option allows you to create new fields, view fields etc.)

image

Click the Finish button & in the appearing page enter some unique fields for the list.

image

Step 5: Include List in Site Definition

Open the onet.xml of Site Definition & Reference the list from it.

image

You need to use the correct Template Id & Feature Id for it.

image

For finding feature id, open the Features > Feature 1 > .feature file > Find the GUID against featureId

Step 5: Deploy

Build & Deploy the solution

Now you are ready to test the Site Definition.

Step 6: Test

Open the Browser > Open SharePoint site > Site Contents > New Sub site

image

After creating the site > Go to Site Contents & you can see the List Instance there.

image

This concludes our Site Definition with List Instance creation.

image

A good read for Site Definition vs. Site Templates

· link

References

http://msdn.microsoft.com/en-us/library/ee231576.aspx

Summary

In this article we have explored a real-world scenario of Site Definition creation with List Instance. The source code is associated with this article.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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