SharePoint Utility to manage Content Type and List Event Receivers


Introduction

Recently I have been building a solution which makes use of Content Type Event Receivers. The event receivers were being deployed using declarative xml for example:-

<ContentType ID=”[Removed]” Name=”My Content Type” Group=”My Content Types” Version=”0″>
<DocumentTemplate TargetName=”/_layouts/CreatePage.aspx” />
<XmlDocuments>
<XmlDocument NamespaceURI=”http://schemas.microsoft.com/sharepoint/events“>
<Receivers xmlns:spe=”http://schemas.microsoft.com/sharepoint/events“>
<Receiver>
<Name>MyEventHandler</Name>
<Type>ItemUpdated</Type>
<SequenceNumber>10000</SequenceNumber>
<Assembly>MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=000000000000</Assembly>
<Class>MyAssembly.EventReceivers.ContentTypeEventReceiver</Class>
<Data></Data>
<Filter></Filter>
</Receiver>
……

Now this normally works great, except when you make a mistake. Its quite well known that upgrading Content Types that have been defined using declarative xml can be tricky.

This is one of the reasons why Microsoft released Feature Upgrades in SharePoint 2010 (if you haven’t seen this then please check out Chris O’Brien’s set of blog posts (http://www.sharepointnutsandbolts.com/2010/06/feature-upgrade-part-1-fundamentals.html) on the subject).

In this case the development was on a SharePoint 2007 environment and I found myself in a situation with deploying Content Type Event Receivers.

It seems that once the Content Type had been deployed and the feature switched on its quite difficult to make certain changes to the content type. This includes changes like the following:-

  • changing a field’s default value
  • changing whether a field is required
  • changing the event receiver definition
    However, unfortunately Gary LaPointe’s stsadm commands would not working correctly for my content type and Gaetan Bouveret’s utility only manages list event receivers but does look very good at that!

Solution

Therefore I started to write my own command line utility. The first version was quickly written to get what I needed to do, done.

I have updated it so that at least its a bit more intuitive but it still only allows you to modify event receivers at a content type or list level.

Please be careful because if you ask it to delete an event receiver then guess what it will delete the event receiver!

As with all these utilities please do not try using this on your production environment without performing some testing on a development environment beforehand.

If you have any comments, problems with the utility please leave a comment and I’ll take a look..

Utility System Requirements:-

  • SharePoint 2007 SP2 (Tested on April 2010 and April 2011 Cumulative Update)
  • Utility must be run from machine which is connected to the SharePoint farm that is being modified.

Usage:-

Console application name: ITSP.EventReceiverConfig.exe

Command Line Arguments:-

  • -url : full url of site that hosts content type or list
  • -mode : [list | add | remove]
  • -targettype : [list | contenttype | assembly]
  • -targetname : [name of list | name of content type | name of assembly]
  • -assembly : [full assembly name including version number etc]
  • -class : [fully qualified class name that is implementing the event receiver]
  • -type : [itemadding | itemadded | itemupdating | itemupdated]
  • -sequence : [number bigger than 1]

The utility with releases, document and source code can be found on Codeplex.

Codeplex Project: http://itspeventreceiver.codeplex.com

Documentation can be found here: http://itspeventreceiver.codeplex.com/documentation

Corrupted List Url Fix: Link to SharePoint List points to /_layouts/listedit.aspx?List=[ListGuid]


Issue

Had an issue at a client where a SharePoint task list got corrupted.

The issue had come about due to the list being copied using Metalogix SharePoint Migration Manager within the same site. The copy of the list had been corrupted so that if you clicked on “View All Site Content”, then clicked on the list name you were taken to the Edit List Settings page (/_layouts/listaspx.aspx?List=[GuidOfList]). Once in the list settings page, clicking on the breadcrumb to take you back to the list would take you to the web application homepage.

Solution

The fix was actually quite straightforward, if you typed in the url of the list correctly, http://sharepointsiteurl/sites/site/lists/My%20List%20Name, you could access the default list view with no problem. So I used a similar method to fix that I have used in this blog post, Manage Content and Structure error.

To fix:-

  • Delete the list using List Settings->Delete this list.
  • Restore the list from the recycle bin

Voila! The link within “View All Site content” is now working as expected.