Creating a Content Type in a Feature is even eaiser than a file provisioner using SPSource.

For this example, I'll just create the files needed to create a Feature for the exisisting Welcome Page Content Type, but this feature is most beneficial when creating a custom Content Type, as yo can use the UI to create the new Content Type in a much shorter time than it takes to create the XML files needed for a new custom Content Type. Remember, we've got two site, one called 'design' and one called 'dev'. Design is where we create items using SPD and the UI, and dev is a mirror of servers further in the deployment cycle.

To start, I create a new file named WelcomePage.spsource
ContentTypeFile.gif

Next, I define the Content Type I want to get out of the Site Content Type list (only Site Content Types are available right now)
ContentTypeDef.gif

When I run SPSource (look at the previous walkthrough to see how) both the column definitions and the content type definitions are pulled down and added to the Visual Studio project. I got started on this part with a little help with code from Andrew Connell, so props go to him for saving me some time.
ContentTypeFiles.gif

One of the benefits is that you can see that the Content Type definition file includes the Content Type ID from the design site, so this is somethign else you dont' have to worry about creating. This is important when coupled with a custom file provisioner that is based on your custom Content Types, as the modules created in SPSource will reference the Content Type ID of your custom Content Type.
ContentTypePostSPSource.gif

All that's needed now is to add the files to the Feature.xml file, and when you deploy the WSP and activate the Feature in the dev site, the new content type will be available.

Last edited Aug 12, 2008 at 4:32 PM by richfinn, version 10

Comments

No comments yet.