Main | Visual Studio 2010: Code Generation »
Thursday
May132010

Creating a custom list definition and instance for SharePoint 2010

1. Open your Visual Studio 2010 SharePoint project and add an Empty Element to your project. This is where you will define your fields for that will be in your custom list.

image

2. In the <Elements> tag add a field node for each column you want to add. For example to add SiteRelativeUrl Text field and Ordinal Number field your elements.xml would look like the following:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Field ID="{5744d18c-305e-4632-8bd2-09d13ff4830d}"
    Type="Number"
    Name="Ordinal"
    DisplayName="Ordinal"
    Group="ConnectProject">
  </Field>
  <Field ID="{5744d18c-305e-4632-8bd3-09d134f4830e}"
    Type="Note"
    Name="ServerRelativeUrl"
    DisplayName="ServerRelativeUrl"
    Group="ConnectProject">
  </Field>
</Elements>

3. Add a new content type to your project with base type Item.

image

4. Modify the elements file in your content type by adding FieldRef nodes for the fields you created in the previous step.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <!-- Parent ContentType: Item (0x01) -->
  <ContentType ID="0x01006f40dd23b61d4cc5b84ee16d666c0943"
               Name="ConnectProject - Menu From List ContentType"
               Group="ConnectProject Content Types"
               Description="ConnectProject menu from list content type"
               Inherits="TRUE"
               Version="0">
    <FieldRefs>
      <FieldRef ID="{5744d18c-305e-4632-8bd2-09d13ff4830d}"
               Name="Ordinal"
               DisplayName="Ordinal"
               Required="TRUE"/>
      <FieldRef ID="{5744d18c-305e-4632-8bd3-09d134f4830e}"
               Name="ServerRelativeUrl"
               DisplayName="ServerRelativeUrl"
               Required="TRUE"/>
    </FieldRefs>
  </ContentType>
</Elements>

5. Add a “list definition from content type” to the project

image image

6. Edit the list instance title and url and you should now have your custom list next time you deploy and activate your feature.

Reader Comments (8)

Thanks for taking the time to talk about this, I feel fervently about this and I take pleasure in learning about this topic. Please, as you gain information, please update this blog with more information. I have found it very useful. Hermes mens belts

November 24, 2010 | Unregistered Commenterhappyttyy

Beautiful blog. Thanks for sharing it.
zee
walisystems.com

November 28, 2010 | Unregistered Commenterzee

Your idea seems inventive enough when i visit here,Fossil rep watchesIts useful for me.Thank you!

April 18, 2011 | Unregistered Commenterbillmiao

Shopping is the best place to comparison shop for Coach Handbags. Coach Outlet Stores are selling imported brand new 100% authentic and genuine Coach Handbags.Coach is the leading global organization dedicated to advancing the coaching profession by setting high standards, providing independent certification bags.

July 21, 2011 | Unregistered CommenterCoach Purses Outlet

Juicy Couture Outlet with a classic as one of the fashion style of competition in the market with high potential and welcome by consumers. If you want to get some savings on your Juicy Couture Handbags (around 25% - 30% off) then check out a Juicy Couture outlet store.

July 21, 2011 | Unregistered CommenterJuicy Couture Bags

replica panerai watches.As far as I'm involved, in some extent, well-known manufacturers might be the particular trendsetters in fashion. That is due to the fact you'll find a number of intellectual, creative along with best designersoperating for sought-after manufacturers.tag heuer 2000

August 1, 2011 | Unregistered Commenterlisayun

It's nice to definitely come across an internet site the location where the blogger is skilled. Thank you for creating your website.
Houton Home Security

October 26, 2011 | Unregistered CommenterHouston Home Security

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>