Sitefinity Toolkit: iCal Event Reminder

By in
No comments

One of the best features of Sitefinity is the Events Module. But while you can easily add and categorize events, and even show a nifty interactive map on the event detail page, there isn’t any built-in way to let your visitors add the event to their Outlook calendar.

Fortunately, with the help of DDay.iCal Class Library by Douglas Day, I was able to bring easily incorporate this functionality. The process basically reduces to this:

  1. Retrieve the Event ID from the event details page
  2. Pass that ID to an ashx handler, which returns an iCal item

Installation and Usage

Of course you need to download the Sitefinity Toolkit and unzip it to your site’s bin directory. Be sure that you download the version that matches your Sitefinity installation, and that you have the included DDay.iCal and antl.runtime libraries, as they are required for this module.

You need to register the ASHX handler for the event reminders. This takes an Event ID and returns an iCal item. Add the following to your web.config:

<httpHandlers>
    <add verb="GET" path="/eventreminder.ashx" type="SelArom.Net.Sitefinity.HttpHandlers.EventReminder" />
</httpHandlers>

If you are using IIS 7 be sure to register the handler in the system.webserver node as well:

<system.webServer>
    <handlers>
        <add name="EventReminder" verb="GET" path="/eventreminder.ashx" type="SelArom.Net.Sitefinity.HttpHandlers.EventReminder" />
    </handlers>
</system.webServer>

Event Details External Template

In order to add the Event Reminder link to your event details page, you must map the Event Details page to an external template. The external template you map MUST include the code behind page, since this is where you’ll be adding code to retrieve the Event ID.

On the front-end (.ascx file) of your external template, add a HyperLink control, which is what users will click to get the iCal item.

<asp:HyperLink ID="CalendarReminder" runat="server" ToolTip="This event occurs in the past" Enabled="false" />

Take special note of the properties that are set here. By default, the link will not be enabled, because for events in the past, there should be no need to set a reminder.

Now we need to set the code that will retrieve the current events id, and if necessary, enable and build the link to the reminder. Add the following to your Page_Load event.

protected void Page_Load(object sender, EventArgs e)
{
    // retreive event item from current view
    var view = Parent.Parent as EventsView;
    var mgr = new EventsManager("Events");
    var ev = mgr.GetEventByContentId(view.SelectedItemId);

    // if event is not in the past
    if (ev.End >= DateTime.Now)
    {
        // build and enable link to reminder
        CalendarReminder.Enabled = true;
        CalendarReminder.ToolTip = string.Concat("Add a Reminder for ", ev.EventTitle, " to Outlook");
        CalendarReminder.NavigateUrl = string.Format("~/EventReminder.ashx?id={0}", ev.ID);
        CalendarReminder.Text = "Add To Outlook";
    }
}

As you can see, we’re using reflection to grab the selected item’s id from the EventsView control that is embedded with our template. There may be a better way to retreive this (especially since SelectedItemId is an obsolete member) but for now, this does the trick.

Next you need to check the event end date. If it’s not yet past, build the link from the event metadata and enable the link.

That’s pretty much all there is to it! If I missed anything please let me know, and if you have any suggestions or comments send them my way as well. If you enjoy this toolkit or any of my other work, please consider kicking a small donation to my studio fund via the sidebar on the right.

The following two tabs change content below.

selaromdotnet

Senior Developer at iD Tech
Josh loves all things Microsoft and Windows, and develops solutions for Web, Desktop and Mobile using the .NET Framework, Azure, UWP and everything else in the Microsoft Stack. His other passion is music, and in his spare time Josh spins and produces electronic music under the name DJ SelArom. His other passion is music, and in his spare time Josh spins and produces electronic music under the name DJ SelArom.