Home Contact

The Frog Pond of Technology

Ripples of Knowledge for SharePoint and Other .Net Technologies

News

 Subscribe to this blog

About Me

Name:
Brian Jackett
Location:
Columbus, OH
Company:
Sogeti USA


Find me on Speaker Rate

Twitter












Article Categories

Archives

Post Categories

Syndication:

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

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

    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


    Feedback

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

    Awesome!!! thanks I have been looking for this for a while... easy to follow and great info 10/21/2009 5:03 PM | Jeff

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

    Hello,
    I have gone through this a few times now and I cant seem to get it right. I an able to activate the feature but the list never shows up. Do you have any ideas?
    Thanks 10/21/2009 5:35 PM | Jeff

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

    Jeff,

    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. 10/21/2009 7:32 PM | Brian Jackett

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

    Thanks for getting back to me... I did remove the <ListInstance> yesterday after I had problems. Now that I have put it back it works great!! I must have had a typo the first time.
    Thanks again for taking the time to create how to's like this. It really helps out people who are trying to learn SharePoint. 10/22/2009 10:52 AM | Jeff

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

    Jeff,
    Thanks for the feedback. I'm always glad to lend a helping hand. My blog is mainly a means of me giving back to the community for all that I've gained from them over the years. Let me know if there are other topical areas you'd like covered. 10/22/2009 5:07 PM | Brian Jackett

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

    Hello again,
    I hate to bug you but I been trying to figure this out and I can't get it to work. If I do the above in its own WSPBuilder project it works. If I try to add a second or third list to the project only the first list every works.

    Do you have any ideas as to why this would happen?

    Thanks again 11/18/2009 5:44 PM | Jeff

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

    Jeff,
    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? 11/19/2009 8:14 AM | Brian Jackett

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

    Thanks,
    yeah it is kind of odd. I can create a feature for a list in a new project and it will work everytime. If I try to create an additional list definition feature within the existing project it never works. I even tried to create 2 projects both with one list definition feature and tested them to make sure they work. I then copy the folder for one of the features into the features folder of the other and only the original feature works. I check to make sure that the Type, template type in the elements.xls are unique and also that the GUID in the feature.xml is not the same.

    Thanks again 11/19/2009 9:57 AM | Jeff

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

    Are you using Wspbuilder or VSeWSS or other? I would recommend trying to add a feature with their wizards if you're using the tools. That way you can reduce the chance of missing required pieces. 11/20/2009 8:08 AM | Brian Jackett

    Post A Comment
    Title:
    Name:
    Email:
    Website:
    Comment:
    Verification: