During the last few days, I have created a way where I am able to produce a List Instance Schema in 10 - 15 mins.
What I am doing is, I am creating a List Instance OOB, Add the New fields as per my business requirement and extracting the schema by saving it in a List Template(.stp file) in such a way that I can use it in Schema.xml definition. This method helps me creating List Instance and package it very fast and makes my task simple.Though some knowledge of schema file gives a better understanding of what we are doing. But any one can do it by following simple steps.
But Before I talk about extracting the List Schema from the List Template. I will be preparing the Solution Structure.
Assumtions: I am assuming that we have already created SharePoint Project in Visual Studio 2010.
Preparing Solution Structure
- In your visual studio instance, Right Click on your sharepoint project and click on Add > New Item.
- From the Wizard, choose the SharePoint List Instance.
- a) Give some name your List Instance(Display Name), I will give this 'MyNewCustomList'
b) Choose a List Template, You can choose any List Template, and choose a List Instance, Let me choose Custom List to keep it simple.
c) Give List a URL, "Lists\MyNewCustomList"
d) Click ok to close the wizard.
- After step 3, we will be having a SharePointItem 'MyNewCustomList' of type List Instance with a element.xml file, instantiating it from TemplateType=100, that will create a custom list with a Title Column in it. But we wanted to add the fields to this custom schema.(In SharePoint 2010 we can create a List Instance without creating a ListTemplate by specifying CustomSchema property for ListInstance. http://msdn.microsoft.com/en-us/library/ms476062.aspx
<ListInstance Title="MyNewCustomList" OnQuickLaunch="TRUE" TemplateType="100" Url="Lists/MyNewCustomList" Description="My List Instance"
- Now Lets Add a Schema.xml File to your SharePointItem.
- Also include this file into your SharePointItem.data file.
This is how we do it it. Click on the your 'MyNewCustomList' in Solution Explorer in Visual Studio. Right click Open Folder in Windows Explorer. Open SharePointItem.Data in notepad
<ProjectItemFile Source="Schema.xml" Target="MyNewCustomList\" Type="ElementFile" />
We are done with Solution Preparation steps.
We will now create a Custom List in SharePoint with ''MyNewCustomList". Go to List Settings and Add the columns, as per the requirement. After doing with all changes whether it is a addition of List Column, Creatiypeng a View, addition of some content Type etc.
- Save this list as Template. Go to Template Gallery, and Download your list template. This file will be a .stp file.\
- Change the File Extenstion to .zip.
- Open the zip file, it will contain a manifest.xml
- Open Manifest.xml file in some nice editor like notepad++.
- Carefully, Locate node "<List>" in this xml. Copy this entire section of <List>...</List> and now paste it in your schema.xml file we created in above steps.
Few Final Modifications and we are done in Schema.xml file.
- Remove the name attribute containing List GUID of your previous List.
<List Name="SomeGUid" ...> remove this Name attribute, we don't need this in our schema
Replace the following nodes <View>
<View BaseViewID="1" Type="HTML" Level="1" ContentTypeID="0x" WebPartZoneID="Main" OrderedView="TRUE" DisplayName="All Links" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/links.png" Url="AllItems.aspx">
Also replace the Forms Node with the below one.
<Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
<Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
<Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
Great we are done, Now we can include this ListInstance in a feature and create a package. Activating that feature will create a ListInstance.
Hope the technique saves a lot of time especially for the beginners 🙂