Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > New Global Events View modes: 
User avatar
Member
Member
Armysniper89 - 4/5/2012 1:49:23 PM
   
New Global Events
I am a bit confused by the content of the documentation on Global Events in Kentico 6.0 http://devnet.kentico.com/docs/devguide/event_handlers_overview.htm

The problem that I cannot figure out is how to setup this in my code. I created a class in App_Code but wasnt sure what to name it...if it had to be a specific named thing to be seen. I called it CustomDocumentEventsLoader.cs. I then added my code but VS 2010 was not picking up on the code sense. Here is my code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CMS.TreeEngine;
using CMS.GlobalHelper;
using CMS.SettingsProvider;
using CMS.SiteProvider;

[CustomDocumentEvents]
public partial class CMSModuleLoader
{
/// <summary>
/// Attribute class that ensures the loading of custom handlers
/// </summary>
private class CustomDocumentEventsAttribute : CMSLoaderAttribute
{
/// <summary>
/// Called automatically when the application starts
/// </summary>
public override void Init()
{
// Assigns custom handlers to the appropriate events
DocumentEvents.GetContent.After += Document_GetContent_After;
}

private void Document_GetContent_After(object sender, DocumentEventArgs e)
{
TreeNode indexedNode = e.Node;

if (indexedNode != null)
{
// get assigned categories
System.Data.DataSet categories = CMS.SiteProvider.CategoryInfoProvider.GetDocumentCategories(indexedNode..DocumentID, String.Empty, String.Empty);

if (!CMS.GlobalHelper.DataHelper.DataSourceIsEmpty(categories))
{
StringBuilder str = new StringBuilder();

// loop through all categories and add them to the content variable
foreach (System.Data.DataRow category in categories.Tables[0].Rows)
{
str.Append("BSpan" + CMS.GlobalHelper.ValidationHelper.GetString(category["CategoryDisplayName"], ""));

}

e.Content += str.ToString();

}

}

}
}
}

User avatar
Member
Member
kentico_michal - 4/6/2012 2:08:18 AM
   
RE:New Global Events
Hi,

You can name the .cs file as you want. You just need to register the event in the following way:
		
public override void Init()
{
DocumentEvents.GetContent.Execute += new EventHandler<DocumentEventArgs>(Document_GetContent_After);
}

Best regards,
Michal Legen