DotNet Development, SharePoint Customizing, Silverlight, MS Infrastructure and other tips and tricks

How to create a new List Item Instance with a Feature

Posted by PANVEGA on January 18, 2009

List Instances

A list instance is a list created by using a list template. When creating a list this way, you can override some of the list properties set in the template, and you can include data rows that will also be created as list items in the list. In this example we gonna create a Custom List Instance called BannerList.

Allowed Scopes

The scopes to which a feature can be deployed, are dictated by the types of elements included in it. A feature with list instance elements can only be deployed to Web Site scopes, since it creates a list in a specific web site.

First create a feature.xml, which I expleined in a previous post. In the next stepcreate a ListInstace.xmlxml file for your List feature.

<?xml version=”1.0″ encoding=”utf-8″ ?>
<Feature xmlns=”; Id=”A4E3B5AB-857C-42d1-961D-4B2A6A2D43A7″
Description=”The feature create a new Custom List Instance”
Hidden=”FALSE”   Scope=”Web”  Version=”″>
<ElementManifest Location=”ListInstance.xml” />

Notes about this feature manifest:

  • The title of the feature is My List Instance Feature.
  • It will be deployed as a Web Site feature, since it’s Scope value is Web.
  • It references a single element manifest file: ListInstance.xml.


<?xml version=”1.0″ encoding=”utf-8″ ?>
<Elements xmlns=””&gt;
Url=”Lists/BannerList”  OnQuickLaunch=”true”
Description=”Contains all Items for the banner function”/>

Note: The FeatureId Attribute value you can get when e.g. creating a new Custom List Instance manually. You find the right ID in the URL:


Instance of a Image Library (Template 109):

Description=”Contains all Images for the BannerList”/>

The element manifest file can have any name you wish (in this example it’s called ListInstance.xml), but it’s root element must be <Elements>. Inside this root element, you can place any number of feature element descriptions. In this example I will present the use of the <ListInstance> element which is used to deploy Lists to SharePoint web sites.

This examples creates a list named My List with the URL Lists/MyList. Here is a short explanation of the attributes of the <ListInstance> element:

  • FeatureId – (optional) The GUID of the feature where the list template was defined. If this attribute is not present, SharePoint will assume that the list template was defined in this feature.
  • Title – (required) Title of the list.
  • Description – (optional) Description for the list.
  • Id – (required) Unique integer identifier for this list instance. It must be unique across this feature.
  • TemplateType – (required) The integer identifier of the list template. This attribute must map to the Type attribute of the list template definition (in the ListTemplate element).
  • Url – (required) Site-relative URL where the list will created.

Other Attributes

There are some other less used attributes that one can use in the <ListInstance> element, which are listed below:

  • OnQuickLaunch – (optional) True if you want the list to be displayed in the QuickLaunch menu (local navigation).
  • QuickLaunchUrl – (optional) Specifies the URL of the view page to open for the list through QuickLaunch navigation.
  • RootWebOnly – (optional) True if the list is only created in the root web site of the site collection.

Here you find a nice List Instance Generatror

Creating lists using ListInstances is quite easy to do within a feature. However, deleting those lists again when deactivating that feature does not happen automatically (which is understandable, since you don’t want to lose all data in the list when accidentally deactivating the feature …). A feature receiver to do the job for you.  The receiver simple deletes all lists created by a ListInstance tag in the feature.

Including Data in the List Instance

When using this type of feature element, you can specify a set of items that will be included when the list is created. For that you must insert a <Data> element inside the <ListInstance> element, as shown below.

<?xml version=”1.0″ encoding=”utf-8″ ?>
<Elements xmlns=””&gt;
Title=”My List”
Description=”List created with a feature.”
<Field Name=”Title”>Item 1</Field>
<Field Name=”CustomField”>Custom Data</Field>
<Field Name=”Title”>Item 2</Field>
<Field Name=”CustomField”>New Custom Data</Field>

This example shows how to add two list items to the list instance. For each of the list items, two fields are updated: Title and CustomField.

More Information:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: