Tuesday, May 19, 2009

SharePoint Event handlers and Windows forms/Console application.

Couple of days back I was working on a windows forms application to add list items using the SharePoint object model. This list had ItemsAdded event handler registered to it using a feature. I noticed that while adding items programatically the event handler was not getting fired, the same worked fine if the items were added using the standard SharePoint interface.

My event handler was making use of some appSettings parameters. These appSettings parameters were included in the web.config while activating the feature for the event handler. It turned out that event handlers are called in the same context as the items being added. The solution was to add the appSettings parameters in the windows forms/ console applications configuration file. After doing so, the event handlers worked when adding items using the windows forms application.