The Filling is the Best Part
In the previous post I showed how to create a list template. In this post we will create an instance of the list and populate it with actual data. This is the real power of a feature for lists. You create the basic Feature.xml and tell it where to look for the Elements.xml file.
In the Elements.xml file you create the following code:
<ListInstance
FeatureId="00BFEA71-DE22-43B2-A848-C05709900100"
Id="1999"
Description="Custom list for the LFI design groups."
TemplateType="100"
Title="LFI Design Groups"
Url="Lists/LFIDesignGroups">
<data>
<rows>
<row>
<field name="Title">35: Chill®</field>
</row>
<row>
<field name="Title">35: Mingle®</field>
</row>
</rows>
</data>
</listinstance>
In the listinstance node you place the feature ID GUID for the feature to base your list instance off of. In the sample code above this is the GUID for the feature of the basic list template. If you do not place a GUID in here, the documentation says that Sharepoint will substitute it with a default one. Don't ever do this as it can screw up the base list templates for the entire server. Always place a GUID in there yourself.
The documentation says that ID is optional but I always include it. It can be pretty much anything, an integer, a string, a GUID. As far as I can tell it is not used by Sharepoint. The only restriction is that it must be unique within the feature.
The description is what you want to show up for the list description. The template type is also grabbed from the list template that you are basing your list on. In this case the list template of 100 is for a custom list.
The title is the title you want to give the list.
The URL is what you want the URL of the list to be.
Inside the listinstance is a data node that contains a rows node and then a row node for each row in the list. Within a row node you place a field node and specify the name of the column that you are going to fill. In this case it is Title. You then place the data inside the node. In this case we are inserting two rows with data of 35: Chill and 35: Mingle. You can place as many nodes as you need to fill your list.
This feature works best if you need to fill a list with static data. You can easily recreate the list later or move the list to a new server such as staging or production.
For more information on list instances:
http://msdn2.microsoft.com/en-us/library/ms476062.aspx
And for more options for a field element:
http://msdn2.microsoft.com/en-us/library/ms437580.aspx
Labels: features, list instance, MOSS, Sharepoint 2007
2 Comments:
thanks for going into a bit more detail, the msdn is awful!!
Yes, the MSDN does not contain as much information as it should. The nice thing is you can add corrections and additions to any page of the MSDN to reflect what you have found when using the technologies.
Post a Comment
Subscribe to Post Comments [Atom]
<< Home