More in this section
Blogs RSS feed

Sample.Events module: Building a pluggable module based on Generic Content module

by User Not Found
Sample.Events module is an uncompleted module that demonstrates how to extend built-in Generic Content module in order to create more robust and complex functionality, yet not spend a lot of time on building already built functionality (like UI, tagging, security…). You can download the module from here.

Generic Content module is a cornerstone module of Sitefinity. On top of it we have already built News module as well as the Blogs module.

Basic idea

Sample.Events module is module that can be used for creating information about various events. The module allows one to enter the name of event, description of the event, tag and categorize the event. Since all this functionality is provided by Generic Content module, it makes sense to build this module by extending Generic Content module. In addition to provided functionality, for every event one or more News categories related to this event can be selected. Also, this module allows to select days on which event is taking place (by using multiple selection on RadCalendar control). While not spectacularly functional module it demonstrates some advanced topics in creating pluggable modules.


We'll start by creating a new module just as we would do it if we are to build a new module from scratch. Pay attention that in web.config we’ll be doing things a bit differently than it was the case with the Sample.Contacts module. If you examine the web.config you'll notice that we are following the same logic as with News or Blogs modules. We add a new Generic_Content provider for Events, set the meta fields (Name, NewsCategories, EventDates) and finally add the Events provider.

The ~/Sitefinity/Admin/ControlTemplates/Events folder has been created by copying all the files from ~/Sitefinity/Admin/ControlTemplates/Generic_Content folder and then making some minor changes (replacing words „Item“ with „Event“ and such...).

Meta fields

As you may already know Generic Content module and modules based on it are capable of storing information in meta fields. While that is a very quick and easy way to modify the module to fit your needs, it does have some drawbacks, which we will alleviate in this demonstration.

Let’s take the NewsCategory meta field for example. Every time user creates a new entry he can define one or more News categories related to this event. These will be saved in NewsCategory meta field as semi-colon delimited strings. So when we open a particular event, we can access the NewsCategory meta field, split the string and get all the NewsCategories related to this event. So far, so good… However, let’s assume that we want to list all the events that are related to particular News category. Obviously, we could scan all the Events and search for the correct string, but that approach would not scale very well.

To solve this problem we are going to create in our Sample.Events module lookup table called EventsNewsCategories. Every time when we save an event, we’ll enter in this table Event id (or ContentID) and the NewsCategoryId it is associated with. So when we want to find all the events that are related to a particular News category, we can execute a simple query against this table and simply load all the needed events, without parsing all the events’ NewsCategory meta field strings.

The question is when are we going to save values to this lookup table? Since it would take a lot of time to modify ControlPanel control (we have simply inherited Telerik.Cms.Engine.WebControls.Admin.ControlPanel class here), we can’t really influence the behavior of that Save button. However, we can extend the provider for Generic Content. So if you open the Sample.Events.Data.DefaultEventsProvider.cs file you’ll see it inherits Telerik.Cms.Engine.Data.Providers.DefaultProvider class. This means will have all the data manipulation methods Generic Content uses. Also, you’ll notice we are implementing IEventsProvider interface just to make sure our Events specific methods are implemented as well.

The idea here is to override SaveContent method and add some additional logic to it. SaveContent is a method of Telerik.Cms.Engine.Data.Providers.DefaultProvider and it saves content to a database (don’t get confused with “Content” part, our Events are nothing more than Content objects, we just call them Events in this module). So in the SaveContent module first we call base.SaveContent(content) and let the Generic Content provider do whatever it usually does to save content, but after that we take our meta fields and save these values to the look up tables. This is the key part of this demonstration.

The same concept is applied to EventDates meta field, only instead of News category ids it saves dates to a lookup table.

Public side

You’ll notice this module has only one public control: EventsCalendar. This control shows the calendar and on the days when an event is scheduled it shows the title of that event. So, what we are doing here is taking advantage of RadCalendar’s DayRender event. We provide an event handler for this event that checks if on that date any events have been scheduled. Since we have a lookup table called EventDates, we don’t need to go through all the events and parse the EventDates meta field, but we simply query a EventDates table for the particular date and return all the events (content) that has been scheduled on that day.


Please bear in mind that this is just a simple demonstration module. You could make it as complicated and feature rich as you want. The important thing is here to see how you can extend Generic Content module and use meta fields for storing complex data (e.g. multiple categories) and then create lookup tables which will make your modules scalable.

You can download the module from here.


Leave a comment
  1. Sean Molam Nov 08, 2007
    Great post Ivan, Uncanny timing, I was just about to start looking into the best way to create an Events listing. I will have to see if this is what I am looking for, but it certainly sounds like it. *click *click me downloading.... I guess at some point in the future you would be able to integrate the rad Scheduler, do you know when that will be included in Sitefinity to achieve this sort of thing, and even though it is still in Beta could it still be used?
  2. Seth Cleaver Nov 26, 2007
    Hi Ivan, thanks a lot for putting this together. Like Sean, I was just thinking about doing this for a couple of module needs. I have put the sample module in a sitefinity dev site, re-added the references to the sitefinity dlls and updated the web.config as per your sample. However firing up the site I get and error: " Missing provider: Events" I am running 3.1 SP1 - I have played for a while but I haven't got any closer to why this error is occurring... I even used your web.config file with no success.
  3. Ivan Nov 29, 2007
    Hi Seth, I am out of the office on the conference, so sorry for not responding sooner. Yes, I know they've invented laptops for that purpose exactly :) Have you referenced the Sample.Events and Sample.Events.Data from your website. Seems to me that the problem is that when you build the solution, .dll files are not output to the bin folder. So when the application is started it looks for the provider (because web.config tells it to), Sample.Events.Data.dll is not present. I hope this helps.
  4. Jan Jan 10, 2008
    Hi Ivan, Can you post a link to a demo of this events module? Thanks!
  5. Jan Jan 10, 2008
    Hi Ivan, Can you post a link to a demo of this events module? Thanks!
  6. Ivan Jan 12, 2008
    Hi Jan, there is no demo of the project. To give it a try you can download the module project and add it to one of your local Sitefinity installations. Web.config is included in the project, so you can see how to register the module with Sitefinity. If you are unfamiliar with adding modules to Sitefinity, you can take a look at this post : Regards, Ivan
  7. nani Jan 14, 2008
  8. Jan Jan 16, 2008
    Hi Ivan, Is this the same module that will be released with Sitefinity 3.2? Thanks!
  9. Jan Jan 16, 2008
    ... or if anyone else has a link to a live working version of this module, I'd love to check it out. Thanks!
  10. Ivan Jan 16, 2008
    Hi Jan, no it's not the same module. The module I am talking about in this post is only meant to be a demonstration for creating custom modules based on Generic Content module. The one that you'll find in Sitefinity 3.2 will serve the similar purpose (announcing events on the website), but will be much more rich in functionality than the sample module here. For example, this module does not support geomapping, which is a part of the official module that will make it in Sitefinity 3.2. Also, thanks for your feedback. I am currently thinking about how to make my samples easier to check out (without installing them first). For starters, I think I'll be publishing more screenshots in the future... and will keep improving on this aspect of my blog.
  11. Romi Feb 25, 2008
    Hi Ivan, I try to implement this module in the new3.2beta. If you compile they are namy errors with the new telerik dll resources . Could you help to update for new 3.2. And we are not the radEditor and Calendar, I need to use the SF3.1 but not yet usable in the future. Sample.Events.UrlRewriterService' UrlRewriteService.cs ERRORS 'Telerik.Web.IUrlRewriterService.GetUrlData()' 'Telerik.Web.IUrlRewriterService.GetUrlData(string)' 'Telerik.Web.IUrlRewriterService.GetItemUrl(object)' .UrlRewriterService' 'Telerik.Web.IUrlRewriterService.Initialize()' Not created And many warnings Could you help us
  12. Seth Apr 17, 2008
    Hi Ivan, I would like to create a generic based module and just basically add additional meta fields in the web.config to create the module I want. Hopefully I view then use the new 3.2 content view, search etc. Would it be possible for you to post a base C# class project with just the base classes etc. in the project you need to begin a basic generic content based module. Thanks
  13. Seth Apr 17, 2008
    Hi Ivan, I think I found one on the forums... I'll let you know.

    Leave a comment