Saturday, 18 August 2012

List Definition & Instance

In my previous post I held your hand through the tough process of declaring some site columns and content types; by tough I mean difficult if you're a nine year old with a learning disability, but hey I'm not one to judge. You can think of this post as part deux, where I will show you how to create a list definition from your content type and then instantiate a list instance from the definition. Sound like a blast? if you said yes, I sympathise with you for my life is just as empty and meaningless as yours. If you said no, well then congratulation and I'd like some fries with that...

Let's get started, create a SharePoint 2010 Project in the same solution called LookUp.Data, this is going to be where our list definitions and list instances are going to reside.

With your Lookup.Data project Created add two folders:

  • List Definitions
  • List Instances

Lets create some list definitions:

  1. Add a new item to the List Definition folder
    • In the left pane select SharePoint 2010, 
    • In the middle pane select List Definition from Content Type
    • Give your list definition a descriptive name, and somehow specify that it's a list definition. I added an _LD but you can do whatever you like.
    • Click the Add button 
  1. Next you'll see the SharePoint Customization Wizard:
    • Make sure to shorten the solution name
    • select the content type you want to build the definition from
    • uncheck the "Add a list instance for this list definition"
now repeat the previous steps to create the Job Posting List Definition, once complete you should end up with something along the lines of:
  1. Now with Both of our List Definitions complete lets go and create some List Instances to match.
    • Right click on the List Instance folder and add a new item.
    • in the left hand pane again select SharePoint 2010
    • In the middle pane pick List Instance
    • Give it a descriptive Name like "Department"
    • Click Add
  1. Next you'll see the SharePoint Customization Wizard:
    • Give your list instance a display name
    • select the List Definition you want to Instantiate
    • Fill out a description
    • specify the URL address for the list
    • and finally decide whether you want it in the quick launch bar, that's really up to you, generally if a list is updated regularly by a user you'd set it to true.
Now with the Department List Instance ready repeat the steps above to create the Job Posting List instance.

Just as before lets clean up our feature:

  • Rename Feature 1 to "Lookup.Data"
  • Double Click the Lookup.Data feature to view the feature manifest.
    • Change the Title to something descriptive
    • Give it a description
    • set the scope
    • and most importantly remember to add all the List instances to the manifest.
Once Complete your Feature Manifest should resemble the following.

Now deploy the Lookup.Data project to deploy our list definitions and instances. Now you need to know that when you deploy a project that contains a list instance two shitty things happen:
  • all list data is cleared
  • the list is assigned a new GUID (that ruins lookup columns)
I mention these because in the next post we're going to add a lookup column and then rewire it.