A while ago I stumbled upon a serious design limitation regarding Content Types and centralized document templates. What then followed was a series of testing, phone calls with Microsoft, finding alternative solutions and deep dive into Office Open XML.
Request from the customer
“We want to use MOSS 2007 to create a collaboration site per project for our 400+ projects. These collaboration sites all use the same Content Types and document templates. We want to centrally manage those document templates so that we don’t need to make the same change 400+ times.”
Approach
Due to sizing we architected a solution with a dozen of Site Collections that would each hold a collection of project sites. We ‘Feature’-ized our Content Types and Site Columns so that they could quickly be activated on all Site Collections and used by the child sites. Document templates would be stored in a central document library and we would link to them in the Content Types on the project sites.
First issue
Linking to document templates really doesn’t play well with the Document Information Panel (DIP). I have blogged about this here:
Centralizing Document Templates in a library- Document Information Panel shows incorrect properties
We proposed a solution where the document templates in the central library would be pushed to the Content Type resource folder on site level. The code to perform the push would have to connect to the Site Collections, copy the template to the resource folder (http://sitecollectionurl/_cts/contenttypename) and link template and Content Type together.
When a Site Content Type is associated with a List it will be a List Content Type inheriting from the Site Content Type and the document template will be copied to the List Content Type resource folder (http://sitecollectionurl/listurl/Forms/contenttypename).
Second issue
Did I tell you that the column values (metadata) have different values based on the project site ? So when a project site is created we automatically update the List Content Type Column default value with the values for that specific project site. Unfortunately this is not supported when working with Office 2007 file formats because they only react on changes to the Site Column.
Consider the following scenario:
1) Set up a document library with a Content Type that has a text column with a default value
2) Upload a new .doc or .docx as Content Type template
TEST 1) Create a new document:
.DOC: the DIP will contain the text column with the default value
.DOCX: the DIP will contain the text column with the default value
3) In SharePoint, modify the default value of the text column
TEST 2) Create a new document:
.DOC: the DIP will contain the text column with the updated default value
.DOCX: the DIP will contain the text column with the original default value
Microsoft confirmed that this is by design.
Third issue
When designing our document templates with Content Controls mapped to our SharePoint fields we didn’t know that internally in the DOCX file it uses a GUID for mapping the Content Control with the SharePoint Metadata XML. For fields (Site Columns) created in the UI or through API this is the SPWeb.ID of where they were created. For fields created declaratively through Features this is the SPList.ID of where their Content Type is associated to.
So some things to notice
- Creating a single document template with Content Controls mapped to your declaratively added Fields cannot be used in two different Document Libraries because the Content Controls lose the connection with Field (because the ID of the List is different and not updated in the Content Control)
- The solution here is to create your fields in the UI or through the API (this could be in a Feature Activating event)
- Copying a document template across Site Collections means different Web ID’s so it also affects fields created in the UI or the API
Finally
In the end we wrote some wrapper classes for Office 2007 file formats using System.IO.Packaging that would manipulate our document templates once they were copied over to a different Site Collection. We also rewrote our Features to create our Fields through the API (SPWeb.Fields.AddFieldAsXml()).
- Remove the SharePoint Metadata XML so that association of the Content Type to a List it would be regenerated automagically
- Loop through every Content Control and find to which Field they were mapped using information in it’s XPath. Then we would update the GUID’s in the Content Control to match the SPWeb.ID
Next time I’ll definitely take these design limitations into account. Lessons learned I’d say !
Every once in a while I get the request to manage all document templates centrally in a Document Library. This can easily be done by configuring your Content Types to ‘link’ to the document template by location and then applying those Content Types to lists on several locations.
However there’s a gotcha in Word 2007 with the Document Information Panel.
Consider the following scenario:
- You have a “MyTemplates” Document Library for storing the Word templates (.doc, .docx)
- You have a “Documents” Document Library configured with Content Types linking to your templates as noted above. These Content Types have custom metadata (text fields, date fields, lookup fields, etc.)
- You create a new document with a given Content Type
When the new document opens in Word 2007 the Document Information Panel is showing properties from the “MyTemplates” Document Library instead of your Content Type. Once you save the document it will refresh and show the correct set of properties. If you have required metadata it will prompt you to fill that in before actually saving.
I believe this to be a bug in Word 2007. It has been confirmed by Microsoft that this is a design limitation.
A workaround An alternative solution for some scenario’s could be to set the Content Type of your templates to the target Content Type.
This would of course still not work when you want to use the same template for multiple Content Types.
Definitely something to keep in mind when planning your setup…
I recently declared an Event Receiver through a SharePoint Feature: Event Registrations

Some of the samples online had surprising elements such as <Data /> and <Filter />. I have never seen them used before and didn’t know their purpose. Perhaps they are not to be messed with ? Perhaps great power lies within ?
- Data – Specifies a string that will be passed as a parameter to the receiver method when handling the event
This one is commonly found in the documentation. It can be used to declare additional information and then the Event Receiver code behind can use this information. Better than hardcoding although I haven’t had the need for it (yet ?).
- Filter – Reserved. Filter MUST be NULL
According to the official docs it is reserved: Event Receivers Result Set
Thank you Thomas for helping me on this one !
Also here’s a good reference: SharePoint 2007 Deployment: Event Registration Features
I'm currently doing quite some research on Event Receivers (ERs) on Content Types (CTs) and activating those CTs on a document library in SharePoint 2007 (WSS 3.0 to be exact, but same applies for MOSS 2007 and MSS(X) 2008).
The setup is a single document library with
- the out of the box Document Content Type (no event receivers defined)
- a custom ContentType1 having an EventReceiver1 for any possible event (ItemAdding, ItemUpdating, ItemAdded, …)
- a custom ContentType2 having an EventReceiver2 for any possible event
In the scenario’s situation ‘A’ has Document as default Content Type, while situation ‘B’ has ContentType1 as default.
Some scenarios
1. Create a new document of type ‘Document’ (New button)
A. No events are fired because there are none defined for this Content Type
None
B. (same as A)
2. Create a new document of type ‘ContentType1’ (New button)
A. The Office client application “knows” the Content Type and will save directly as that and fire the defined events
EventReceiver1.ItemAdding, EventReceiver1.ItemAdded
B. (same as A)
3. Create a new document and save it to the document library (starting from Word)
A. The Office client application will ask the Content Type before saving and fire the events defined for that Content Type
None
B. (same as A)
4. Upload a document using the Single File page
A. All ItemAdding events fire. The default CT is assumed. Afterwards the user is presented with the option to change the Content Type which will trigger ItemUpdating and ItemUpdated for the destination Content Type
EventReceiver1.ItemAdding, EventReceiver2.ItemAdding
B. All ItemAdding events fire. The default CT is assumed. Other events defined for that Content Type also trigger
EventReceiver1.ItemAdding, EventReceiver2.ItemAdding, EventReceiver1.ItemAdded
5. Upload a document using the Multiple Files page
A. All ItemAdding events fire. The default CT is assumed
EventReceiver1.ItemAdding, EventReceiver2.ItemAdding
B. All ItemAdding events fire. The default CT is assumed
EventReceiver1.ItemAdding, EventReceiver2.ItemAdding, EventReceiver1.ItemAdded
6. Copy and paste a document of type ‘Document’
A. All ItemAdding events fire. The Content Type of the source file is assumed
EventReceiver1.ItemAdding, EventReceiver2.ItemAdding
B. (same as A)
7. Copy and paste a document of type ‘ContentType1’
A. All ItemAdding events fire. The Content Type of the source file is assumed. Other events defined for that Content Type also trigger (only Update, not Add)
EventReceiver1.ItemAdding, EventReceiver2.ItemAdding, EventReceiver1.ItemUpdating, EventReceiver1.ItemUpdated
B. (same as A)
8. Restore a document of type ‘Document’ from the Recycle Bin
A. All ItemAdding and ItemAdded events fire
EventReceiver1.ItemAdding, EventReceiver2.ItemAdding, EventReceiver1.Added, EventReceiver2.ItemAdded
B. (same as A)
9. Restore a document of type ‘ContentType1’ from the Recycle Bin
A. All ItemAdding and ItemAdded events fire
EventReceiver1.ItemAdding, EventReceiver2.ItemAdding, EventReceiver1.Added, EventReceiver2.ItemAdded
B. (same as A)
10. Restore a previous version of a document of type ‘Document’
A. No events fire
None
B. (same as A)
11. Restore a previous version of a document of type ‘ContentType1’
A. The ItemUpdating and ItemUpdated events defined for the Content Type fire
EventReceiver1.ItemUpdating, EventReceiver1.Updated
B. (same as A)
Lessons learned
- All ItemAdding events trigger in case of file upload via WebDAV or the Upload page
- Copying a file triggers the ItemAdding and ItemUpdating events, but not the ItemAdded event
- Restoring from the Recycle Bin triggers all ItemAdding and ItemAdded events regardless of Content Type
- Restoring a previous version is seen as an update (makes sense)
I’m starting to see the light although I do think that the Recycle Bin thing is a design flaw. Be careful on how you implement Event Receivers. Currently I’m thinking an additional check on Content Type in your code might be the safest way to ensure your code doesn’t run accidentally for a different Content Type ? What do you think ?