El Blanco's Office 2007 Blog

Friday, August 31, 2007

Event Receiver Management

One of the things from SPS 2003 that didn't make it into MOSS 2007 was a way, via the UI, to specify an event receiver for a document library. This seems bizarre considering the facts that you can now have multiple event receivers for a single document library, and you can now have event receivers on lists as well as document libraries.

To get around this I've developed the "Event Receivers Manager" solution, which I've uploaded to CodePlex (http://www.codeplex.com/elblanco). This is the first of the free add-ons I intend to release for things that really bug me about SharePoint – watch this space for more useful things in the future.

Once you've downloaded the solution you can install it as normal for SharePoint:

stsadm –o addsolution –filename C:\BlancoWorld.EventReceiversManager.wsp

Then when added to the solution store you can either deploy via the Central Administration site or via the command line:

stsadm –o deploysolution –name BlancoWorld.EventReceiversManager.wsp –immediate –allowGacDeployment

This will install the "BlancoWorld SharePoint Event Receivers Manager" feature as a site collection feature – activate this feature and you'll now be good to go . . .

From a list's settings page within SharePoint will now be a new link called "Event Receivers":

Clicking on this link shows all the event receivers for the list: Using the drop-down menu you can delete existing event receivers:

Or edit existing event receivers:
You can also click the "New" toolbar button to add a new event receiver – you must specify the type, assembly name, and class name:

I hope others find this add-on useful, please leave me comments regarding any issues or improvements you'd like to see. Planned improvements at this stage are:

  • The site map provider functionality that provides the breadcrumb is not 100% there yet – I need to spend more time on it.
  • I'd like to enable column sorting on the page that lists the event handlers to allow the user to click on the column headings to sort the event handlers.
  • The "Edit" functionality from the drop down menu only actually lets you view the details. I intend to amend this to allow you to edit the properties.
  • The "Delete" functionality from the drop down menu takes you to a separate page to confirm deletion – I'd like to make this a client-side confirmation.
  • When adding a new event handler I intend to add functionality allowing you to also specify the Sequence.

I've released it as-is since I thought it might be useful for others – if you have any opinions on which of my planned improvements you'd like to see first, then let me know. Also if you have any other improvements you'd like to see, again, let me know.

Enjoy !

Adding a Picker to the “Send to -> Other Location” Menu Option

A colleague of mine and right-on SharePoint dude, Mark Wilson, has posted an entry on how to add a picker to the page that is displayed when you select the "Send To -> Other Location" option from the ECB menu.

Personally I think this is great as it's a big PITA to have to type the URL to the destination library manually.

Check it out here.

Friday, August 24, 2007

Adding the 12 hive to VS.NET File Dialogs

This is something that has bugged me for ages but I've never got around to finding the time to look at it - wouldn't it be nice to have a shortcut to the 12 hive in the left-hand shortcuts panel in the Open, Save, Add New Item etc. dialogs in VS.NET – I know I'd like it !! Kudos to my new colleague Stephen Kaye for taking the time to find out how to do it.
  • Open Word and click on File -> Open to display the Open File dialog.
  • Navigate to the 12 hive.
  • Right-click in the left-hand shortcuts panel and select "Add 12" from the pop-up menu:


  • This will have added a shortcut to the 12 hive to your dialogs within Word.
  • Now open regedit and navigate to HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Common\Open Find\Places\UserDefinedPlaces.

  • Assuming that you only have one custom location defined (i.e. the 12 hive you've just added) then there'll be a key called "Place0" – right click on this and export it somewhere, say to your desktop and call it "word.reg".
  • Edit the word.reg file in Notepad or your favourite text editor (mine being Notepad++) and replace the key string at the top of the file with the following instead:

    [HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\Open Find\Places\UserDefinedPlaces\Place0]

    Your file should now look like this:


  • Save this file and close the editor, and then double-click on the word.reg file on your desktop to enter the new information into the registry.
  • Voila – you'll now have the 12 hive as a shortcut in your dialogs within VS.NET.

You can also do a similar thing with document libraries etc to open / save files directly to web locations.

Hope this is useful.

Wednesday, August 08, 2007

Cancelling a Running Workflow Programatically


I got asked recently how to cancel a running workflow, so I thought I'd post the solution here for everyone . . .


The first step is to get an instance of the SPWorkflow object that represents the workflow that is running on the SPListItem in question. This can be performed as follows:


foreach (SPWorkflow wf in listItem.Workflows)
{
    if (wf.ParentAssociation.BaseId == <Guid from workflow.xml>)
    {
        if (wf.InternalState == SPWorkflowState.Running)
        {
            // Need to cancel wf here . . .
        }
    }
}

Once you've got the running SPWorkflow instance as indicated above, you now need to cancel it. This is performed by calling the CancelWorkflow method of the SPWorkflowManager class passing in the SPWorkflow instance:

SPWorkflowManager.CancelWorkflow(wf);