Creating a custom list definition and instance for SharePoint 2010
Thursday, May 13, 2010 at 4:48PM 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.
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.
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
6. Edit the list instance title and url and you should now have your custom list next time you deploy and activate your feature.
Rory |
8 Comments |
SharePoint