Exporting A SharePoint Site Into A Feature: Part 3 – Exporting the Lists

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.

ExportSharePointSite11a     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. ExportSharePointSite11b

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.

ExportSharePointSite8c    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.

ExportSharePointSite11c

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.

ExportSharePointSite11d     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.

ExportSharePointSite11e     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.

-Frog Out

10 thoughts on “Exporting A SharePoint Site Into A Feature: Part 3 – Exporting the Lists

  1. Originally posted on: https://briantjackett.com/archive/2009/07/13/exporting-a-sharepoint-site-into-a-feature-part-3-ndash.aspx#491210Jeff, There are two main ways to get a list instance (ListInstance from site def or from feature), but I only recommend from a feature. Make sure you have a <ListInstance> element inside your elements.xml file and that the cutome type value is identical to the one in your <ListTemplate> element (as shown in picture 4 on this post.) Next, make sure your elements.xml file is properly referenced inside the feature.xml file inside a <ElementsManifest> element (as seen in picture 5.) You may want to check your ULS logs to see if it shows any exceptions at the time you activate your feature. If those are all in order and you’re still having issues let me know. I’d be willing to take a look at your code if need be.

    Like

  2. Originally posted on: https://briantjackett.com/archive/2009/07/13/exporting-a-sharepoint-site-into-a-feature-part-3-ndash.aspx#494873Jeff, Are you attempting to add a second and third list to the same feature? I believe you can only have one list definition per feature, but you can have multiple list definition features per project (I have 4 on my current project.) Also, when you say only the first ever works do you mean you get an error or just that the others aren’t available for creation?

    Like

  3. Originally posted on: https://briantjackett.com/archive/2009/07/13/exporting-a-sharepoint-site-into-a-feature-part-3-ndash.aspx#495790Jeff, I’m at a loss for what is missing in your situation. If you take the export from the SharePoint Solution Generator and plug each list template feature into a separate feature in your project you should be able to add multiple. You are activating (or feature stapling in a site definition) each feature into your site correct? Let me know if you are able to find a fix in the future.

    Like

  4. Originally posted on: https://briantjackett.com/archive/2009/07/13/exporting-a-sharepoint-site-into-a-feature-part-3-ndash.aspx#496892Hello, I ran through your List Export, thanks for the info. It worked for me and they are deploying as features however when I activate and then try to add data to them it only ever allows me to add data for the title. I don’t get it because I can see all of the columns that I added to the list in both the list settings and on the list itself. But when I try to add a  new record the form that opens only asks me for the Title, the other fields are not there. Has this happened to you before? Thanks

    Like

  5. Originally posted on: https://briantjackett.com/archive/2009/07/13/exporting-a-sharepoint-site-into-a-feature-part-3-ndash.aspx#496893Clarence, Sounds like you need to assign a content type to your newly created list. By default a list supports the out of the box List Item content type which only takes a Title. Read Part 4 (linked above) of this series and see if that helps get you started adding a content type to your list. If not feel free to send me any questions you have.

    Like

  6. Originally posted on: https://briantjackett.com/archive/2009/07/13/exporting-a-sharepoint-site-into-a-feature-part-3-ndash.aspx#496989Hello,I tried part 4 and I dont know what to select with the Imtech tool. The List I created is just called countries, it has the default title and a single line of text field called Value. I found the countries list and exported the Value field to the elements.xml. I do not know what to do for the content type. Since I did not create a content type but used the existing “single line of text” I thought all I had to do was find that type and export it. Can you please let me know what I am supposed to be looking for here.Thanks again

    Like

  7. Originally posted on: https://briantjackett.com/archive/2009/07/13/exporting-a-sharepoint-site-into-a-feature-part-3-ndash.aspx#497046Clarence, Have you created your content type (and site columns) on a SharePoint site yet? It must be created by hand first before you can export it using my steps. If you haven’t created it yet, follow the steps at the below link. It gives a nice entry level walkthrough of what to do and look for. After you have your content type created on a site, you should be able to find it in the Imtech Fields Explorer under Content Types for the site you reference. From that point follow my steps in part 4. Let me know if you run into any issues.http://office.microsoft.com/en-us/sharepointtechnology/HA100974931033.aspx

    Like

Leave a Reply

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

WordPress.com Logo

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

Facebook photo

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

Connecting to %s