Do you remember the times they asked you to create a feature for the creation of all custom content types and site columns for this new MOSS 2007 project ? Most of the time you would prepare your self for a long struggle with the CAML XML language and the many options it offers you to create everything you need.
Thanks to some clever tools on the web and a little bit of work, you can do this job in a matter of minutes. I will quickly describe the procedure to do this really fast:
1. Create the columns
Fire up your dev machine and go to the site columns list. In there, create all the site columns you need. Don't forget to put them all in a new group so all our custom site columns are nicely grouped. This will help us later on.
2. Create the content types
On your dev machine, go to the site content types list. Create all your content types, inherit from existing content type if needed and complete them with custom site columns. Also put all the custom content types in a new group.
3. Download Andrew Connell's stsadm extensions
Go to http://www.andrewconnell.com/blog/articles/MossStsadmWcmCommands.aspx and download the latest version of the installer. It's a wsp. Install and deploy it on your dev machine.
If everything went right, you will now be able to execute some new and very interesting stsadm commands.
4. Extract the CAML XML for the site columns and content types
Open up your command line and execute the following command:
STSADM.EXE -o GenSiteColumnsXml -url http://wcm -outputFile "c:\siteColumns.xml" -groupFilter group
and type in the correct url to your site collection (where you created the site content types and site columns) and a destination for the CAML XML file. Also provide the correct group name so we don't extract all site columns.
Then execute this command, again with the correct parameters:
STSADM.EXE -o GenContentTypesXml -url http://wcm1 -outputFile "c:\contentTypes.xml" -groupFilter group
5. Do some small xml manipulations
The site column xml file can be used instantly in any feature. All site columns will be created correctly. You will notive however an 'extra' property: SourceID. The official MSDN documentation for this can be found here: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfield.sourceid.aspx. After extraction this property contains a GUID, the default value would be 'http://schemas.microsoft.com/sharepoint/v3'. Anyway, this property will not in any way have an influence on the correct working and installation of your custom site columns.
Unfortunately, the xml for the content types isn't always right. If you inherit from a content type, references to the site columns of this content type will also be included in the xml definition. Of course this is not needed because we are inheriting. So delete all the site columns that are part of the parent content type anyway.
Also delete possibly included 'XmlDocuments' tags as these are also not needed in our custom content types:
You can now also use this xml in any feature and it will correctly create your content types.
If, after installation of your site columns and content types, you try to go to the content types overview and the loading of that page is very slow (and infact will never show up), there is still some unneeded xml in the definition of the content types.
6. Conclusion
Using this method I can now create features for content types and site columns in minutes without having to struggle with the CAML xml too much. Also, all the properties are set correctly by the GUI so no problems there either. In my next post (which will not be today because it's very late) I will explain how you can also create lookup fields using a feature.
Geen opmerkingen:
Een reactie posten