With the new event model in WSS 3.0 we have the ability to cancel some user actions on the behalf of synchronous events like ItemUpdating or ItemDeleting.
To do this you have to implement an event handler: Create a class library with a class that inherit from Microsoft.SharePoint.SPItemEventReceiver. And then override the desired event methods (ItemDeleting, ItemUdating, …).
Now you have to register your event handler within SharePoint. You can do this programmatically through the object model or declaratively through a feature for a specific list type or a specific content type. Details are well documented in the WSS SDK. There is also a nice book excerpt about the whole story of event handling in WSS: http://www.wrox.com/WileyCDA/Section/id-306329.html
To cancel an event you can use the following code in your event handler:
public
override
void ItemCheckingOut(SPItemEventProperties properties)
{
properties.Status = SPEventReceiverStatus.CancelWithError;
properties.ErrorMessage = "Operation not allowed because...";
properties.Cancel = true;
}
With ItemDeleting or ItemUpdating this is working perfectly: the user action will be canceled and the user will be presented the custom error message "Operation not allowed …".
But with ItemCheckingOut is something wrong. The user action (Check-out) is canceled but the user will be presented the following system error message instead of our custom error message:
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
I also tested this with WSS/MOSS SP1 (Technical Preview) and got exactly the same behavior.
Did anyone come across this issue (bug?) or does anyone know a workaround?