Welcome to Atlanta .NET Regular Guys Sign in | Join | Help

SharePoint 2007 Event Handlers - Some work, some don't.

Since late last year (2005), I have been playing with and testing the SharePoint 2007 betas.  Most of the testing I have been doing has been end user related thru the UI, I haven't done much development.  About 6-8 weeks ago, right before the time that the Beta2TR came out, I started doing some development.  The project I am currently on is a SharePoint 2007 extranet and there is a custom web part I need to write so I thought it was a good idea.  Some of the technologies being used in this project include Active Directory (AD), SQL Server 2005 (SQL 2005), SQL Server 2005 Reporting Services (SSRS 2005), Microsoft Identity Integration Server 2003 (MIIS 2003), Microsoft Internet Security and Acceleration Server 2006 (ISA 2006) and of course, Microsoft Office SharePoint Server 2007 (MOSS 2007).

 

In a nutshell, the piece of this huge puzzle that I want to discuss is adding users to SharePoint groups.  The security model in SharePoint has changed somewhat, simplified you might say, although a little less granular.  MIIS 2003 manages identities.  In our case, extranet users are stored in a SQL Server database somewhere.  There are existing systems in place that manage these users and they do not need to be changed, at least not during this project.  What MIIS 2003 can do is look at these users and then provision AD accounts as necessary.  It can be configured to add/update/disable users in AD as necessary.  Essentially, you write C# code to do this however you want, for example, what pattern to use when creating a username and stuff like that.  MIIS stores previous states so you can see if a user needs to be added, updated or disabled.  It does this out of the box.  What it cannot do out of the box is add users to SharePoint 2007 groups.  The details of this product and all of the things it can do are outside the scope of this post as well as outside the scope of my skill set, so I will leave that up to you, to learn about in your spare time :)

 

The approach we are taking is to write a custom MIIS 2003 rules extension.  Essentially, after MIIS 2003 does something with a user, we have an opportunity to do something else.  In this case we will be calling into the SharePoint web services and adding/removing user to specific groups based on properties stored in the MIIS metaverse and AD.  This approach will work fine, but led me to think of possible alternatives.

 

Last week I attended a MindSharp SharePoint 2007 Developer summit taught by Todd Bleeker.  Todd is an excellent speaker and it was 5 days of some darn good developer training.  We covered a boat load of topics.  One of the topics we covered was event handling.  Event handling in SharePoint 2007 has dramatically improved in this version.  In v2 (2003) we only had synchronous event handlers, meaning we could only write code to do something "after" something happened in SharePoint.  Now, in the new version we also have asynchronous event handlers, meaning we can write code to do something "after" something happens and also "before" something happens.  This is a huge improvement and will be welcomed with open arms by SharePoint developers.  You might be saying to yourself, wow, Microsoft actually listened.  Yes, they did, but there are, of course, some caveats.

 

We now have access to many new events.  I have tested many and many do not work yet in the Beta2TR (I hope they fix them!).  I'll leave that for another post.  In the previous version, we could attach an event handler to a specific list.  We can't do that anymore.  Now, we have to attach an event to a list template.  The SDK defines many list templates, for example Announcements are 104.  Check out the following screen shot.

 

 

I tested the "Deleting" event.  This event fires right before an item gets deleted.  I successfully tested this event on an announcement list and prevented items from being deleted; actually, what happened is irrelevant, the point is that the code worked and did what it was supposed to do.  I started to think about how I could apply this on my current project.  I had an epiphany and thought hey, if I can write an event that fires after items are added/updated/deleted from an announcement list shouldn't I be able to do that for the user list as well?  It is just a list.  It should have events.  Most SharePoint developers know that when if you view source on a list view there are a bunch of hidden fields towards the bottom of the page.  One of those fields is the list template id.  If I do this for an announcements list I see the following line:

 

ctx.listTemplate = 104;

 

This is the list template id used when attaching events.  So an event attached to this list template id would fire for every announcements list.  I could filter by list name or id in my code if I wanted to to give me the same functionality of hooking an event up to a particular list,  a little less performant as it would be checking on every list.  Also worth mentioning is that this event handler can be scoped to a single site if needed so it wouldn't be used on all announcements lists in a farm necessarily.

 

Since, the users are stored in a list, I thought I would check to see what the list template id was on a that list, then, in theory, I could hook events up to that list.  Here is the HTML markup snippet from a view source on that page:

 

ctx.listTemplate = 112;

 

Well golly, I don't see that list template id in the SDK screen shot above.  That tells me that this may not be supported or if it is it isn't documented yet.  I wonder how many other "secret" ids there are in the product.  Just for fun, I started poking around the content database to look for the rest of these list template ids.  I spent about 15 minutes on this task and decide to give up for the time being.  I couldn't find anything and Law & Order was more interesting.  What I tried doing was change the list template id in my working event handler from 104 (Announcements) to 112 (All People).  I then went and deleted a user from the site collection.  I also made sure that my event handler was scoped correctly so it would fire for this web site.  To make a long story short, well, shorter, after  muchos testing, the event did not fire.

 

I am disappointed but will continue to test and research this issue as newer builds come out.  If anyone has any input/ideas, please let me know!

Published Monday, October 23, 2006 5:53 AM by Dan Attis
Filed Under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Event Handlers

Wednesday, October 25, 2006 6:11 PM by Stacy Draper et al

# Event Handlers

Dan Attis got all fired up about Event Handlers.  Then he blogged about it http://devcow.com/blogs/jdattis/archive/2006/10/23/1797.aspx&nbsp...
Wednesday, October 25, 2006 6:11 PM by Stacy Draper

# re: SharePoint 2007 Event Handlers - Some work, some don't.

read more about (confirmed) problems with moss2007 event handlers in my blog: www.spstips.blogspot.com
Wednesday, October 25, 2006 6:38 PM by Ishai Sagi

# re: SharePoint 2007 Event Handlers - Some work, some don't.

You are now part of the BUZZ, Sharepoint BUZZ

Visit http://www.sharepointbuzz.com
Wednesday, October 25, 2006 8:36 PM by Kanwal

What do you think?

(required) 
required 
(required)