Create Site Definition with List Instance
In this article I provide a practical example as in the following:
- You need to create a Site Definition
- When the user creates a new site from this Site Definition, a new List Instance is also created
What is the Solution?
We can have any of the following solutions for this:
- Use Feature Stapling
- Use Event Handler
- Use Site Definition
I would recommend the third approach since it is the shortest path.
Procedure
Use the following procedure for the solution:
- Create SharePoint Solution Project
- Create Site Definition
- Create List Definition
- Include List in Site Definition
- Deploy
- Test
Step 1: Create a SharePoint Solution Project
Run Visual Studio 2012 and create a new SharePoint project.
Choose the Farm Solution option as in the following:
Step 2: Create Site Definition
Choose the Solution then select "Add new item" > "Site Definition" as in the following:
Enter a name for the site definition.
Step 3: Create List Definition
"Add a new item" > "List" as in the following:
Enter a name for the list instance. Choose the option custom and click the Next button of the wizard.
(The custom option allows you to create new fields, view fields and so on.)
Click the Finish button and in the page that appears enter some unique fields for the list.
Step 4: Include List in Site Definition
Open the onet.xml of Site Definition and Reference the list from it.
You need to use the correct Template Id and Feature Id for it.
For finding the feature id, open the Features then select "Feature 1" > ".feature file" then find the GUID against the featureId.
Step 5: Deploy
Build and Deploy the solution.
Now you are ready to test the Site Definition.
Step 6: Test
Open the browser then select "Open SharePoint site" > "Site Contents" > "New Sub site".
After creating the site go to the Site Contents and you can see the List Instance there.
This concludes our Site Definition with List Instance creation.
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 explored a practical scenario of Site Definition creation with List Instance. The source code is associated with this article.