When working with custom Lists you find yourself often redeploying the List and creating some test data to verify that everything is working correctly. Entering sample data may be fun to do once but becomes rather boring after a few times. Find out how to reuse your sample data in the development process using Mavention Import List Instance.
SharePoint Lists and test data
SharePoint Lists are a great place for storing data in SharePoint. They are very flexible, highly customizable and out of the box contain rich functionality. Not surprisingly SharePoint Lists are being used in many solutions.
The very base of every SharePoint List is its schema: the definition of Site Columns and Content Types which can be used to store your data. Just like when working with databases, it can be challenging to modify the schema once it has been deployed, especially if the List contains some content.
When developing custom SharePoint Lists one way to find out if everything works as planned is to fill the List with test data and run some tests. Although it might be tempting to fill in fields with random data depending on their type, it might be better to spend some more time and provide real-life information instead. This might not only help you discover some edge cases about your solution but it is also more intuitive to end users should you want to gather their feedback as well.
The challenge with filling lists with real-life data during the development process is that there are no generators that understand your business and your scenario. So you can either create one yourself, which can get very time consuming, or fill in the data every time you modify the List schema and create a new build, which is also far from desirable. There is however yet another option…
In the perfect world
Wouldn’t it be great if you could enter the test data once, store them separately from your List’s schema and then reapply the data over and over again during the whole development process doing nothing more than minor changes to the data so that it fits the new schema? If that’s what you want, Mavention Import List Instance might be just the right solution for you.
Mavention Import List Instance is an extension for the Visual Studio 2010 SharePoint Developer Tools that allows you to import List Instances and their data into your SharePoint Project. After importing the List Instance to your project you can include it in one of your Features and create your List prefilled with test data with a single mouse click!
How it works
As an example I’ve created a custom List that contains names of all Mavens. Although in this case I created the List manually, it doesn’t really matter how you would create that List as long as it’s there.
After installing Mavention Import List Instance a new menu item is added to every List node in the Server Explorer.
After clicking the menu item, the extension will import the selected List to your SharePoint Project as a List Instance SharePoint Project Item (SPI).
Important: for the Import operation to work, you have to have a SharePoint Project open and active in Visual Studio.
As you can see, the Mavention Import List Instance extension includes all field values in the imported List Instance SPI. To keep your test data clean and manageable it might be a good idea to remove all the unnecessary fields such as Created, Author, etc. Values of most of those fields cannot be imported anyway and are generated automatically by SharePoint.
Tip: Removing unnecessary fields can be doable if you have only a few rows but can quickly become a tedious process. In my next article I will show you how you can remove unwanted fields from the exported List Instance using XSLT and Visual Studio.
The only thing left for you to do now is to add the imported List Instance SPI to a Feature and the next time you will deploy your Solution and activate that Feature your List will be filled with some sample data.
The great part is that this approach works with new lists as well as existing lists.