It’s my birthday

December 26, 2006

Hip hip hooray…it’s my birthday…pretty sad that I would be blogging first thing on my birthday, but hey it’s a nerd thing to do.

Advertisements

Christmas 2006 and my birthday

December 25, 2006

It is nearly midnight on Christmas night 2006, so that means that it is almost my birthday… Happy Birthday to me! Merry Christmas to everyone and have a safe new years.


Event Handlers in WSS v3

December 19, 2006

Those that are familiar with event handlers on Document Library lists in WSS v2 will be excited to know that event handlers can now be attached to any type of list. Not only do we get access to the Asynchronous events such as ItemAdded, we now also get access to Synchronous event before the fact, like ItemAdding. This will allow greater control over the way in which lists can be used within WSS v3.

This article will set out to describe the step by step instructions for defining an event handler and then hooking it up to a WSS list.

Creating the event handler

Creating an event handler is extremely simple, use Visual Studio .NET 2005.
1. Add a reference to the Microsoft.SharePoint assembly.

2. Create a class that inherits from one of the new event receiver classes, like SPItemEventReceiver or SPListEventReceiver.

3. Implement an override method for the event you wish to implement. Something like the following;

using Microsoft.SharePoint;

public class ListEventHandler : SPItemEventReceiver
{
public override void ItemAdded(SPItemEventProperties properties)
{
SPListItem listItem = properties.ListItem;
listItem[“ColumnName”] = “Hello”;
listItem.Update();
}
public override void ItemDeleting(SPItemEventProperties properties)
{
properties.Cancel = true;
properties.ErrorMessage = “Deleting items from the list is not permitted.”;
}
}

The ItemAdded event will set a column in the list called “ColumnName” to a value of ‘Hello’ and the ItemDeleting event will be cancelled with an error message displayed to the user.

4. The next step is to sign the assembly and deploy it to the GAC.

That is it; we have created our event handler and deployed it ready to a list to start consuming it. The next step is to register the event to be fired from a given list.

Registering the event handler with the list

In the previous version of WSS you could register the event handler using the SharePoint user interface. This facility has been removed in WSS v3. Registering the event handler in WSS v3 can be done in two ways, as a feature or via code. I will describe the registering via code method. For more information on creating a feature the article called “Working with Features” in the WSS SDK documentation.

The easiest way to register the event handlers against the list is to create a Console application, like the one below;

public class Program
{
static void Main(string[] args)
{
SPSite collection = new SPSite(“http://server/site/”);
SPWeb site = collection.OpenWeb();
SPList list = site.Lists[“MyList”];

string asmName = “MyEventHandlers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f90218d0785d9063”;
string className = “MyEventHandlers.ListEventHandler”;

// Register the events with the list
list.EventReceivers.Add(SPEventReceiverType.ItemAdded, asmName, className);
list.EventReceivers.Add(SPEventReceiverType.ItemDeleting, asmName, className);

// Clean up the code
site.Dispose();
collection.Dispose();

// Return to calling environment : Success
Environment.Exit(0);
}
}

Basically, the code attaches to the SharePoint site and locates the list “MyList” then adds an item to the EventRecievers collection of the list for each event to be fired.

As you can see it is pretty easy to deal with the new event handlers in WSS v3. Happy coding.


Australia is in a drought

December 18, 2006

This picture was sent to me by my future sister in-law Deneale. It was taken at Lake Wendouree in Ballarat. Lake Wendouree was the venue for the 1956 Olympic Games rowing and is all but dry presently. This once full lake that was home to hundreds of birds and fish is now completely dry due to the drought that is affecting the vast majority of Australia. It is going to take a lot of rain to fill this lake again.

Mo-vember update

December 2, 2006

The MOSSIG team was able to raise $718 in donations for movember. This amount will be matched by the company I work for SDM. So a total donation of around $1450 has been raised. I think this is excellent and enjoyed growing my mo. I have however removed it as it didn’t really suit and the itchness wasn’t really growing on me.


MOSSIG / Victoria .NET Hands on Dev Day

December 2, 2006

Today I am helping run the MOSSIG and Victoria.NET hands on development day at Cliftons in Melbourne. We are running two streams. Stream 1 is on the new .NET 3.0 framework and stream 2 is on Office 2007.

Presenting in the Office stream are the MOSSIG team Ben Walters, Ed Richard, Tim Wragg and myself.