Creating List Instance Schema in SharePoint 2010


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

  1. In your visual studio instance, Right Click on your sharepoint project and click on Add > New Item.
  2. From the Wizard, choose the SharePoint List Instance.
  3. 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. 
  4.  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”
    CustomSchema=”
    MyNewCustomList\Schema.xml” />

  5. Now Lets Add a Schema.xml File to your SharePointItem. 
  6. 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. 

  1. Save this list as Template. Go to Template Gallery, and Download your list template. This file will be a .stp file.\
  2. Change the File Extenstion to .zip.
  3. Open the zip file, it will contain a manifest.xml
  4. Open Manifest.xml file in some nice editor like notepad++.
  5. 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.

  1. 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
  2. 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.

    <Forms>

    <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 />

    </Forms>

    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 🙂 

Comments (7)

  1. Vardhaman Deshpande says:

    Hi Saurabh. I have tried creating a list through using the CustomSchema attribute as you mentioned. The list and the views are being created fine. But when I reference the views from a XSLTListViewWebPart, I am not able to see the views. I think if you want to reference the views in web parts, you have to create the list through ListTemplates only.

  2. Kishore Arvapalli says:

    Good work Saurabh!!!

  3. Anonymous says:

    Thanks – certainly helped me.

  4. Arjun says:

    I have problem With my STP file.When i save the file with .zip.windows unable to open it.

  5. Sp says:

    Thanks dude !!

  6. Mark says:

    Hi Saurabh, Using your steps I was only able to create a list definition (no idea how). I too got the problem with the rename of the stp file to zip but was able to rename the extension to CAB and then extract the manifest. The reference to SharePointItem.Data; is this the file SharePointProjectItem.spdata?

    Thanks,

  7. Thanks mark for pointing out the typos, I will updated that in the blog. It is to be a .cab file. Yes also the file is SharepointProjectItem.spdata

Skip to main content