- Part 1 – The Tools
- Part 2 – Exporting the Site
- Part 3 – Exporting the Lists
- Part 4 – Exporting the Site Columns and Content Types
- Part 5 – Wrap Up
So let’s recap where we’re at with this series. Part 1 was about the tools I’ve been using to export a SharePoint site to a feature, part 2 exported the base (pages, web part settings on pages, etc) of the site template, and now part 3 will be exporting SharePoint lists into our feature. The tool we’ll be using time around is the MOSS Feature Generator (previously called CT Feature Creator among other names.)
As I stated in part 2, I prefer the output from the MOSS Feature Generator to that of the SharePoint Solution Generator 2008 because it required less modifications to fit into my WSPBuilder solution. When you launch the tool, click File > New > ListTemplate Feature. Next specify your site collection Url, the individual site that contains the lists to be exported, and the list itself.
The next screen contains a whole host of boxes, but we’ll only touch on a few of the more important ones. Obviously you’ll want to specify a Name and Description for starters. Next take a look at the Type (first red box below) box. The value will typically be the base list template id that your list is already inheriting from. Read this post for a little explanation on each template id. As you’ll see, 100 is the generic list template id. Since we’re trying to create a new list template, you’ll want to create a unique id. I typically choose values above 10000 since the out of the box list template id’s don’t currently go that high. Feel free to come up with your own system.
The other box I’ll highlight is DisallowContentTypes. If you’re using content types on your list (and I recommend doing so for organization and consistency sake,) then you’ll want to pay attention to this later on. I haven’t found a way to set this during the export process, so we’ll take care of that after placing it into our feature later on.
Referring to our picture from part 2 on the solution layout, you’ll want to take your output files and place them into your solution as seen below.
Next, open the elements.xml file. First thing to notice is that I have added some additional markup that you won’t find in the output from our list template creator. I’ve added <ListInstance> and <Module> nodes so that my list template is instantiated within my feature. Feel free to model your file similarly, but not necessary. Lastly, make sure the Type (and TemplateType if you add the list instance) value is a unique value.
Next, open your feature.xml file. The only modification I have done here is make the feature scoped to the web since a list lives on an individual site (web) instead of at the site collection (site) level.
The last (and probably most important) file is the schema.xml one which defines the infrastructure of our list. As you’ll see below, I’ve outlined the addition of two key pieces. First is the EnableContentTypes attribute of the <List> element which has been set to True so that we can have custom content types. The second highlighted piece is the definition code for our custom content type. Don’t worry if you don’t have (or know how to get) that XML snippet. I’ll be covering that in part 4 of this series. For now though, you have a rough sketch of your list template.
As a quick aside, I’ve noticed one thing by working with the schema.xml (and onet.xml from the site template in part 1) file very frequently. When I need to make a change to these files (add a fieldref, change view query, etc) I’ve become faster and more efficient at editing the raw file versus updating through the UI and exporting a new copy. Reminds me of my time working with Unix and VI at a previous job.
So there we have it, second piece of our site template exported into our feature. Part 4 will be focusing on exporting site columns and content types. In the past that used to be a very complex and hard to manage portion of the process, but with new tools that is not the case anymore. Stayed tuned for that installment and in the meantime post and comments or questions you may have. Thanks for tuning in.