Getting the out of a SharePoint List

I was working recently on a project for a client, to build a feature that will create several list templates, content types, and instances of those lists. To do so, I used a great new utility that can be found on CodePlex, written by Jeremy Thake and Rich Finn, that will handle this for you. Better than the SharePoint Solution Generator that ships with VSeWSS (Visual Studio extensions for Windows SharePoint Services).
I used SPSource (the above mentioned program) to extract the content types, list templates, and list instances with ease, just needing a few minor tweaks, but I also had a different issue. I needed to populate those list instances with the data that currently existed within those lists. Jeremy Thake had pointed out that this could be done easily with PowerShell, but there is also another method that works easily enough, without requiring code.
To do so, go to your list which contains the data, and then go into the settings for that list, and save the list as a template, including the content.
Once you have created the list template, go to the list template library, and download the STP file that was created. Now, here is the trick, rename that file from Listname.stp to STP files are nothing more than cabinet files.
From: image
To: image
Once it has been renamed, open the cabinet file in your favorite compression utility, and open the Manifest.XML file that is inside it in your favorite XML editor. SharePoint Designer works great for this, as there is a quick utility to clean up the XML off of your right-click context menu to Reformat XML.
Once you have a nice clean view, do a search for <Data>, and you will then see the <Data> which you can then paste into your ListInstance element within your solution, and you have your data rows from your list, which will be added into the list when the list instance is created.
Copy everything within the <Data> element, including the <Data> tags, starting here (see below), and you should be good to go.
I generally trim off all of the fields that are not needed, and just keep my fields which I am using, for example, in the above, just trimming out everything but my fields. Which should generally all appear at the top of the <Row> element, as shown below.
All of the system fields will be generated automatically, and you do not run the risk of trying to push data into a list that is not supported, such as Created By field authors not being in the sites or farms where these are deployed to, or specifying the Attachment when the resulting list does not support them, you may receive an error on feature activation.
I am eventually planning to write a PowerShell script, or an executable to take care of this, and when I do, I will post about it here, and publish it to our CodePlex site.

About Geoff Varosky
Geoff Varosky is a Senior Architect for Insight, based out of Watertown, MA. He has been architecting and developing web based applications his entire career, and has been working with SharePoint for the past 15 years. Geoff is an active member of the SharePoint community, Co-Founder and Co-Organizer of the Boston Area SharePoint Users Group, co-founder for the Boston Office 365 Users Group, co-organizer for SharePoint Saturday Boston and speaks regularly at SharePoint events and user groups.

3 Responses to Getting the out of a SharePoint List

  1. Sandeep says:

    Is it not possible to add items to list first then save them as template 🙂

  2. Geoff says:

    Sandeep,It is very possible, you may have just misunderstood (or possibly my bad on the explanation!) the process I went through above. I had created the content types, site columns, and lists first within a site, used the SPSource utility to extract the list templates, list instances, site columns and content types into a feature. I then utilized built in list functionality to save the list as a template, to include content. Then using that template with the included content, to extract the data itself to include within the new feature.Hope this clears things up!

  3. Mario says:

    Hello, What happen when there is to much data, that you cannot create an .stp file?

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 )

Facebook photo

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

Connecting to %s

%d bloggers like this: