Share via


Creating Several List Instances in a Single Feature

I’m not sure why I didn’t find this earlier, but I have always put a single list instance definition into a single feature.  However, I recently had to put together several inter-related lists into a feature (no single list was useful by itself).  The first approach was to create each list instance as a hidden feature and then have a visible feature that activated the hidden features through code in the feature receiver.

This just didn’t seem like a good way to maintain this going forward since I ended up with several hidden features, which I don’t really care for (I’d rather everything be visible).  So I tried putting all the list instances into one feature, with subfolders for each list, but I saw strange behavior.  Lists would have fields included that were part of another list definition.  What was going on?

So I started doing some hunting around and it turns out that you can do what I wanted, you just couldn’t take the list templates as they were straight from an export (I always make my lists by creating them in the SharePoint UI and then exporting using SharePoint export or another tool).

First, you need to change the Type attribute of the ListTemplate element in the elementManifest.xml file and, in the same file, change the TemplateType attribute of the ListInstance element to match the new Type value.  It turns out that the ListTemplate Type value only needs to be unique within the feature, so make all of your Type values different (I ended up making all the Type values different across the entire solution so I could easily move list definitions between features until I got ready to release).  It seems that the default export type value is always 100, which confused SharePoint into adding fields from multiple templates with that Type within the same feature.