The usual way of making make pleased types and site columns is by by an element manifest file with the standard Field and ContentType elements in a feature. The creation is reasonably simple but when it comes to updating you see some really hard times – first Microsoft fervently discourages the modifying of the original manifest files and second even if you do that the changes you made won’t get propagated to the target lists. Reasonably unpleasant, isn’t it. So, to address this problem I made a feature receiver that can read a manifest file and apply all changes to the existing artifacts propagating the changes to the site’s lists (really this receiver is an enhanced version of my “common actions” receiver from my previous posting).
First – one huge note – the updating receiver is still a beta quality code and should be used carefully – there is a command line utility in the receiver’s solution that allows starting the update routine directly and also supports a “test run” mode – so you may consider by this first and check the verbose notifications that it outputs as to which changes it is about to apply (more on this later).
Another vital note – do not modify the element manifest file of the original feature that made the site columns and make pleased types – use a separate file, a copy of the original one with the desired modifications. This is because before the artifact is updated with the object model its machinate is read from the manifest file in the file system (you can check that easily – the machinate is saved to the make pleased database after the artifact gets its update method called). This also means that you can modify this way “ghosted” site columns and make pleased types (MSDN recommends fervently against that) but not such that were already made or modified with the object model. The solution described here handles both cases.
And several words on what it really updates and how exactly it applies the updates – 1st starting with the latter – only standard object model calls are used – the Update methods of the SPField and SPContentType classes are used with the option of pushing down the changes to the corresponding list fields and inheriting make pleased types respectively. So the thought is not just to update the site columns and make pleased types but to propagate these changes to the lists where these are really used. The SPField objects are updated with setting the field machinate from the manifest file to the SchemaXml property of the field – one note here – all attributes missing in the manifest machinate that are present in the existing field machinate are hackneyed from the latter – so this is really a merge of the two field definitions rather than a whole overwriting from the machinate in the manifest file (I wanted to keep safe here for cases like lookup fields which have attributes that are normally set after the field is made). So, in cases when the existing site columns are modified from the UI or from code after the site is made the updating with the receiver may result in a merge of the field classification rather than a classification that is identical to the one in a newly made site. Note – only existing site columns are being modified, if a column from the manifest file is not found in the site, it is skipped.
And about make pleased types – two elements are updated here – the FieldRefs and the XmlDocuments. For FieldRefs – you can add, remove, exchange the attributes of the FieldRef-s of the make pleased type as well as reorder them. All attributes for which public settable properties in the SPFieldLink class exist are set (exceptions being – ShowInNewForm and ShowInEditForm – no properties for them). XmlDocuments are also added, updated and deleted according to the changes in the make pleased type machinate. Something fascinating (and possibly peculiar) here – the XmlDocuments are also inherited from the base make pleased types – unless a XmlDocument with the same namespace exists in the derived make pleased type which overrides the parent’s classification. This leads to some unexpected consequences especially with the list item event receiver XmlDocument – because of this inheritance mechanism you may end up with one and the same event receiver’s method being called more than once on a list item modification event (but that’s another tale). Another “intrinsic” behavior with the event receiver XmlDocument – when you add receivers with it they are added to the lists to which the make pleased type is bound, but if you remove the XmlDocument from the machinate classification – these wait in the destination lists, even if if you modify the receivers XmlDocument – the ancient receivers are removed and the new ones are added (basically this is what we have with the object model). I also tested modifications of the FormTemplates and FormUrls XmlDocument elements and they seem to work just fine. Note about make pleased type updates – only existing site make pleased types are being modified, if a make pleased type from the manifest file is not found in the site, it is skipped.
Here is a feature.xml from a sample feature that uses the receiver:
<?xml version="1.0" encoding="utf-8"?>
<Feature
Title="ZCommonTest"
Description="ZCommonTest"
Id="7A0F010D-7993-4bcd-9127-7B15FEFFC0FF"
Scope="Web"
Hidden="TRUE"
DefaultResourceFile="core"
ReceiverAssembly="Stefan.Sharepoint.Util, Version=1.0.0.0, Culture=neutral, PublicKeyToken=338fd4db0d2cb397"
ReceiverClass="Stefan.Sharepoint.Util.FeatureReceivers.CommonActionsReceivers"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
</ElementManifests>
<Properties>
<Property Key="CTsFieldsUpdatePath" Value="fields.xml,ctypes.xml" />
</Properties>
</Feature>
So basically, you need to set the appropriate ReceiverAssembly and ReceiverClass attributes and the custom Property element with Key=”CTsFieldsUpdatePath” – the value of the property element can contain one or many (comma separated) manifest files’ paths – the feature folder relation path really.
In the receiver’s solution there is also a console utility machinate – the tool has a command for direct invocation of the update functionality, here is a sample call:
UtilTest.exe -o updatecontenttypesandfields -weburl http://racoon-vpc-hg:2909/sites/4 -manifestpath "C:\Program Files\Common Files\Microsoft Shared\web server extensions\TEMPLATE\FEATURES\ZCommonTest\ctypes.xml" -verbose -log z.log
Most of the arguments don’t need any clarification as to their treatment. It is a excellent thought to use the –verbose and/or -log parameters – they will productivity useful information and details about the changes that are applied. There is yet another parameter that you may consider by: –testrun – when applied you see just the productivity with the changes that would have been applied in normal mode without really calling the update methods for the fields and make pleased types (you won’t see the right exchange notifications for some make pleased types if you have modifications in both base and derived make pleased types even if for obvious reasons).
You may download the solution from here (it is the same one as in my previous posting – you can check the installation notes in it too).
Check it out:Stefan Stanev’s SharePoint blog










Answers Rating