Web developers wiki ASP.NET Sitecore Sharepoint Kentico by Evident Interactive

Kentico CustomEventhandler: how to

Modified: 2011/05/11 16:19 by jim - Categorized as: Csharp, Kentico, Visual Studio
Edit

How to create your own EventHandlers for Kentico events.

Easiest way to think of a use for your own EventHandlers is that after creating or saving an item, you want to set some value in a Document Node. Here's a step-by-step explanation how to do this.

1. Open an explorer and navigate to the location where Kentico is installed. This is not the website, but some place inside the Program Files. (I always wondered why Kentico installation would want to do anything else than just copy files to my website, no I know) On my computer this is the path: C:\Program Files (x86)\KenticoCMS\5.5R2\CodeSamples\CustomEventHandler
2. Copy the CustomEventHandler folder to a location adjecent to your website.
3. Include the project in your solution file. (Visual Studio 2010 will convert the project, no worries)
4. Add a CMSUseCustomHandlers key to the appSettings section of your web.config and set its value to 'true'
5. Resolve all the missing references in the CustomEventHandler references section
6. Remove the current CustomEventHandler reference in your website project
7. Add a reference to your CustomEvenHandler project in the website project
8. Make sure the CustomEvenHandler project references the following libraries:


CMS.GlobalEventHelper.dll.
CMS.TreeEngine.dll
CMS.GlobalHelper.dll
CMS.SiteProvider.dll
CMS.CMSHelper.dll
CMS.SettingsProvider.dll
CMS.DataEngine.dll
CMS.EmailEngine.dll
CMS.WorkflowEngine.dll


(Maybe you need to add some more references that are referenced by these libraries. Your compiler will tell you soon enough)

Now we are ready to code:
1. Open the CustomTreeNodeHandler class file in the CustomEventHandler project
2. Cast the parameter objects to the right classes:
TreeNode for the treeNodeObj
TreeProvider for the tree
3. Do some stuff to your TreeNode object that Kentico did not facilitate.
4. Use CMS.WorkflowEngine.DocumentHelper.UpdateDocument to store your changes
5. Check out all the other awesome events you can break into.


Happy coding

 © Evident Interactive BV