blog community

Welcome to blog community Sign in | Join | Help
in Search

Wouter van Vugt

This blog is no longer maintained and has moved

Provisioning content types with templates using the feature framework

In this post I will show you how to use the WSS v3 feature framework to deploy a custom solution containing

  • The Litware Base feature
    • A site column
    • A content type tied to the site column
  • The Litware Timesheet feature
    • A derived content type, with a document template

There has been written a lot about the new WSS v3 feature framework. While I am enthusiastic about it, there are still some weird things you need to work with. I will not go over the details of what the feature framework can do for you, others have invested time there already. Let's go over the solution (which you can download here).

The Litware base feature

This feature installs the common elements for Litware Inc. Two items are included, a site column and a content type, both represented as xml files tied together using a feature.xml file. First let's walk through the custom site column:

<?xml version="1.0" encoding="utf-8" ?>
<
Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <
Field
        
ID="{78E36B63-D7E3-4ffa-A853-F5BFE83ABCF0}"
        
Group="Litware"
        
Type="User"
        
Description="Litware Author of the document"
        
DisplayName="Litware Author"
        
Name="LitwareAuthor"
        
Title="Litware Author" />        
</
Elements>

Just basics going on here, the site column derives from the default 'User' type. Next up is the Litware document content type. There is a bit more complexity in that file.

<?xml version="1.0" encoding="utf-8" ?>
<
Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <
ContentType     
        
ID="0x010100B75D4C1C24B445189CC3AF2717191A5A"
        
Name="LitwareDocument"
        
FeatureId="{04D8A0B0-631B-4a40-A23F-BE91776ADE44}"
        
Description="Base content type for Litware documents"
        
Group="Litware"
        
Hidden="TRUE"
        
Version="1">
        <
FieldRefs>
            <
FieldRef ID="{78E36B63-D7E3-4ffa-A853-F5BFE83ABCF0}" />
        </
FieldRefs>        
    </
ContentType>        
</
Elements>

The most difficult part here is the ID value of the content type. It declares the content type inheritance by using sort of sequential IDs. MSDN has a nice article about how that stuff works, find it here: http://msdn2.microsoft.com/en-us/library/aa543822.aspx. (This is absolutely weird to me, and one of the reasons I do not tend to think of WSS as a development platform, more like a tool)

The Litware Timesheet Feature

Now for the reason of this blog post. Below you will find the XML required for creating a content type (same as above), only this time with a document template attached to it. There are two files you will need to hack up, the xml defining the content type and the feature.xml file. Both need to reference the document template.

First let's go through the content type xml file:

<?xml version="1.0" encoding="utf-8" ?>
<
Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <
ContentType
        
ID="0x010100B75D4C1C24B445189CC3AF2717191A5A01"
        
Name="LitwareTimesheet"
        
FeatureId="{E55FF79F-35F5-4c34-8A25-5FB41825ACA3}"
        
Description="Litware Timesheet Documents"
        
Group="Litware"
        
Version="1">
        <
DocumentTemplate
            TargetName="/_cts/LitwareTimesheet/LitwareTimesheet.docx" />
    </ContentType>
    <Module 
        
Name="LitwareTimesheet" SetupPath="Features\LitwareTimesheet"
        
Path="" Url="_cts/LitwareTimesheet">
        <File Url="LitwareTimesheet.docx" />
    </Module>
</Elements>

A few interesting things to note here, first of all the content type ID. It is structured in a few parts: 0x0101 defines it derives from Document, the GUID following is unique to my solution, the 01 in the end defines it derives from the LitwareInc Document type. Next is the DocumentTemplate element, here you define where the menu item on the dropdown will be pointing. All content type templates are stored under the '_cts/<contentTypeName>' folder, and the targetName needs to be defined accordingly. Using just the 'DocumentTemplate' element is not enough, you also need a Module to actually provision the file. The Module element contains the relevant information. First the Name, which is not that important I believe. The SetupPath declares a relative path into the features folder starting from the wss template folder, pointing to the location in the feature where the template file can be found. The File Url points to the location within the features and _cts folder naming the file.

To finish it off, the Feature.xml file for the Litware Timesheet feature also requires a pointer to the template document:

<?xml version="1.0" encoding="utf-8" ?>
<
Feature xmlns="http://schemas.microsoft.com/sharepoint/"
    
Id="{E55FF79F-35F5-4c34-8A25-5FB41825ACA3}"
    
SolutionId="{96560A5F-94C0-46b8-85C9-962318CFA18A}"
    
Scope="Site"
    
Version="1.0.0.0"
    
Hidden="False"
    
Title="Litware Timesheet"
    
Description="Litware Inc Timesheets"
    
Creator="Wouter van Vugt">
    <
ActivationDependencies>
        <
ActivationDependency
            
FeatureId="{04D8A0B0-631B-4a40-A23F-BE91776ADE44}"/>
    </
ActivationDependencies>
    <
ElementManifests>
        <
ElementManifest Location="LitwareTimesheetContentType.xml"/>
        <
ElementFile Location="LitwareTimesheet.docx"/>
    </
ElementManifests>
</
Feature>

Just for fun I have included a solution package which installs the features. Just run an stsadm –o addsolution –filename LitwareTimesheet.wsp and activate the solution from the central admin.

Published Monday, April 02, 2007 2:26 PM by wouterv

Comments

 

Marc said:

Great post ! it helps me a lot, thanks for the saved time ! I have a question, Have you manually created the LitwareTimesheet folder (under _cts) and manually dropped the LitwareTimesheet.docx file ?
April 19, 2007 10:51 AM
 

wouterv said:

Nope, that's due to the content type definition:

   <Module

       Name="LitwareTimesheet" SetupPath="Features\LitwareTimesheet"

       Path="" Url="_cts/LitwareTimesheet">

       <File Url="LitwareTimesheet.docx" />

   </Module>

So no manual actions required, as it should be with the new solution framework.

April 19, 2007 10:58 AM
 

Bram said:

There is a slight adjusment needed for second level site-collections. You need to change the: to Without the forward slash in TargetName at the start. Then it will use the rootweb as starting point. Good luck!
September 21, 2007 3:40 PM
Anonymous comments are disabled

This Blog

Syndication

News


Add to Technorati Favorites
Powered by Community Server, by Telligent Systems