If you're creating a module that has RSS capabilities, such as a blog module, perhaps you want to make your RSS easily accessible to visitors on your site. To do this the latest web browsers, such as IE or FireFox, support the ability to pick up an RSS feed from a page. If you want your DNN module to do this the keep reading.
Here's a quick function I threw together (in C#)
public void SetRssUrl(string rssUrl, string rssTitle)
{
if (rssUrl != null && rssTitle != null)
{
LiteralControl lc = new LiteralControl();
StringBuilder sb = new StringBuilder(400);
sb.Append("<link rel=\"alternate\" type=\"application/rss+xml\" href=\"");
sb.Append(rssUrl.ToString());
sb.Append("\" title=\"");
sb.Append(rssTitle.ToString());
sb.Append("\">");
lc.Text = sb.ToString();
DotNetNuke.Framework.CDefault tp = (DotNetNuke.Framework.CDefault)this.Page;
if (tp != null)
{
tp.Header.Controls.Add(lc);
}
}
}
What does it do?
First it takes in the URL of your RSS Feed, the title you want to give the RSS Feed.
Then it builds up a literal control for the <link>.
Then we grab the "Page" from DNN, and add the literal control to the Header section of the page.
I've done this in the module I'm using for a blog on my personal website, and uploaded the latest code to my site. If you visit the site www.chrishammond.com you should see the RSS icon in your browser is enabled on my homepage and blog pages.
I hope that's helpful for some of the other module developers out there. I've been meaning to look into how to do this for a long time, it's quite simple once you understand what is going on.