Sitefinity: Rss Feeds for Generic Content - Part 1: Setting Up

After finally getting my music back online earlier this week, the next logical step was to get my Dark Synthesis Podcast back online. Unfortunately, Sitefinity (the CMS this site uses) does not have built in support for podcasts. In fact, the Generic Content Module (which I am using to publish my music, and eventually hopefully my videos) doesn’t even have support for general rss feeds! Fortunately to me, however, this wasn’t a setback; it was yet another opportunity to dive deeper into Sitefinity and learn to do something new!

In a recent forum on the Sitefinity forum, I discussed how to implement rss feeds for Sitefinity intra-site modules. This actually works great, and if any one is interested I’d be glad to make a more detailed blog entry about how this is done… But this site doesn’t use custom modules (not yet anyway); music and videos are published using the Generic Content module. The only Rss providers built into Sitefinity are for Pages, Blogs, and Forums.

Fortunately, in what is turning out to be a life-changing moment, I discovered Reflector, possibly one of the greatest tools a .NET developer can have! With it, I was able to take a peek at the existing rss providers (I used the Blog Rss Provider as an example) and use them as a guide to build my very own implementation for the Generic Content Module!

As a result I’m proud to begin the first of a three-part series on how to create an Rss Feed from the Generic Content Module. Part 1 introduces the various classes and controls that need to be created. Part 2 will show you the various methods that need to be overridden within each class. Finally Part 3 will show you how to turn your Rss Feed into a Podcast!

Okay enough back story… let’s get to the code!

Required Classes

There are three classes that will need to be created: a ChannelProvider, RssSettings, and RssView. I’ll introduce each class briefly here, then go into more detail of each one later on in this post.

The real meat of the Rss feed comes from the ChannelProvider and RssSettings classes; rhe RssView class is only used to show a read-only view of the Rss settings in the Services page, so a full implementation isn’t required. Since I didn’t really use this, but since it is required, I’ll just display the minimum code which I used to get it functioning:

using System;
using System.Collections.Generic;
using System.Web;

public class GenericContentRssViewControl : System.Web.UI.WebControls.CompositeControl, Telerik.Framework.Rss.IRssViewControl{
    #region IRssViewControl Members

    IDictionary<string, string> _settings;
    public void InitializeSettings(IDictionary<string, string> settings)
    {
        _settings = settings;
    }  

    #endregion}

Now you need to create a class that inherits from the RssChannelProvider. The basic overrides are below, but we’ll be jumping back and forth as we create the additional classes.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Net;
using Telerik.Rss;
using Telerik.Cms.Engine;

public class GenericContentRssProvider : RssChannelProvider{
    public override void Initialize(IDictionary<string, string> settings)
    {
        base.Initialize(settings);
    }

    public override string Name
    {
        get { return "Generic Content"; }
    }

    public override string Description
    {
        get { return "Rss Provider for the Generic Content Module"; }
    }
}

You are also going to need to create a RssSettings class, but instead of inheriting, we’ll be implementing the IRssSetings interface. This class also needs to contain within it a ControlContainer class. This container class is the link between this settings class and the actual ascx user control that renders on the admin webpage.

using System;
using System.IO;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Cms.Engine;
using Telerik.Cms.Engine.Configuration;
using Telerik.Cms.Engine.Security;
using Telerik.Cms.Web.UI;
using Telerik.Security.Permissions;
using Telerik.Framework.Rss;
using Telerik.Rss;

public class GenericContentRssSettings : CompositeControl, IRssSettingsControl{
    private PropertyDescriptorCollection properties;
    private PropertyDescriptorCollection Properties
    {
        get {
            if (this.properties == null)
            {
                this.properties = TypeDescriptor.GetProperties(this);
            }
            return this.properties;
        }
    }

    private ITemplate controlTemplate;
    private ControlContainer ctrlContainer;

    public string ControlTemplatePath
    {
        get {
            object obj2 = this.ViewState["ControlTemplatePath"];
            if (obj2 == null)
            {
                return "~/Sitefinity/Admin/ControlTemplates/Generic_Content/RssSettingsControlTemplate.ascx";
            }
            return (string)obj2;
        }
        set {
            this.ViewState["ControlTemplatePath"] = value;
        }
    }

    private IDictionary<string, string> settings;
    public void InitSettings(IDictionary<string, string> settings)
    {
        this.settings = settings;
    }

    #region IRssSettingsControl Members

    public IDictionary<string, string> SaveSettings()
    {
        settings = new Dictionary<string, string>();
        return settings;
    }

    #endregion protected class ControlContainer : GenericContainer<GenericContentRssSettings>
    {
        public ControlContainer(GenericContentRssSettings owner) : base(owner) { }

    }
}

In addition to these basic classes, we also need the front-end editor web control for editing feed settings in Sitefinity. This is basically a User Control that contains the various input fields for the Rss Feed settings we want to be able to modify, including Title, Description, number of items, etc. This is also the User Control that is referenced in the ControlTemplatePath property shown above.

I used the Blogs Rss Settings Control (from the /sitefinity/admin/controltemplates/blog folder) as an example, and here is what I came up with. Notice how I’ve included a dropdownlist control so that you can select the data from the specific available content providers.

<div class="RssGenericContentChannels"> 
    <ul> 
        <li runat="server" id="providerNameLi"> 
            <label>Content Provider</label> 
            <asp:DropDownList runat="server" ID="ProviderList"></asp:DropDownList> 
        </li> 
        <li class="selector clearfix"> 
            <asp:Label ID="Label8" runat="server" AssociatedControlID="postUrl"> 
                <asp:Literal ID="Literal1" runat="server" Text="Post Url" ></asp:Literal> 
                <cc1:LabelToolTip HelpBoxCssClass="HelpBox" id="labelHelpBox3" runat="server" ToolTipTitle="" ToolTipText="" AlternateText=""></cc1:LabelToolTip> 
            </asp:Label> 
            <asp:TextBox runat="server" ID="postUrl"></asp:TextBox> 
            <asp:LinkButton runat="server" ID="selectPostUrl" Text="Select Url" CssClass="picker" ></asp:LinkButton>
        </li> 
        <li class="count clearfix"> 
            <asp:Label ID="Label3" runat="server" Text="Item Count" AssociatedControlID="itemsCount"></asp:Label> 
            <asp:TextBox runat="server" ID="itemsCount" ValidationGroup="feedSettings" Text="15"></asp:TextBox> 
            <em class="quont">items</em> 
        </li> 
        <li class="clearfix"> 
            <asp:Label ID="Label6" runat="server" Text="Syndication Type" AssociatedControlID="syndicationType"></asp:Label> 
            <asp:DropDownList runat="server" ID="syndicationType"></asp:DropDownList> 
        </li> 
        <li runat="Server" id="summaryLengthLi" class="count clearfix"> 
            <asp:Label ID="Label5" runat="server" Text="Summary Length" AssociatedControlID="summaryLength"></asp:Label> 
            <asp:TextBox runat="server" ID="summaryLength" ValidationGroup="feedSettings" Text="500"></asp:TextBox> 
            <em class="quont">symbols</em> 
        </li>
        <li> 
            <label>Category</label> 
            <asp:DropDownList ID="CategoryList" runat="server" />
        </li> 
    </ul>
</div>

So that's the basic setup, you need to define the three classes as well as the User Control that contains the input fields for editing the feed settings. In my next post, I’ll discuss and show you the various methods in these classes that need to be overridden to provide access to editing and saving these settings, and finally to create the feed itself.

Stay tuned!

Enjoyed this post and/or found it useful?
SelArom Dot Net Profile Image
SelAromDotNet

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.



Scroll to top