Kentico CMS allows you to publish content using a RSS 2.0 feed. The default installation contains a simple CMSPages\NewsRss.aspx page that shows how to build your own RSS feed. It works with news items, but you can modify the code so that it displays a different type of documents.
The following figure shows the code of the rss.aspx page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RSS.aspx.cs" Inherits="RSSNews" %> <%@ Register Assembly="CMS.Controls" Namespace="CMS.Controls" TagPrefix="cc1" %><?xml version="1.0" encoding="utf-8" ?> <rss version="2.0"> <channel> <title>News RSS</title> <link><![CDATA[<%=HttpContext.Current.Request.Url.AbsoluteUri.Remove(HttpContext.Current.Request.Url.AbsoluteUri.Length - HttpContext.Current.Request.Url.PathAndQuery.Length) + HttpContext.Current.Request.ApplicationPath%>]]></link> <description>News RSS Feed</description> <cc1:cmsrepeater ID="NewsRepeater" runat="server" OrderBy="NewsReleaseDate DESC" ClassNames="cms.news" TransformationName="cms.news.rssitem" SelectedItemTransformationName="cms.news.rssitem" Path="/news/%"></cc1:cmsrepeater> </channel> </rss> |
As you can see, the page contains only RSS elements with dynamic code. The RSS items are rendered using a CMSRepeater control with appropriate transformation.
The code behind looks like this:
[C#]
protected void Page_Load(object sender, EventArgs e) { Response.ContentType = "text/xml"; } |
This code changes the output content type to XML.
How to Create a RSS Feed for a Different Document Type
If you want to display articles instead of news in your RSS feed, you will need to follow these steps:
1. | Create a new ASPX page called articles_rss.aspx. |
2. | Copy and paste all code from the rss.aspx file except for the <%@ Page %> directive. |
3. | Change the following properties of the CMSRepeater control: - SelectNodesOrderBy="DocumentModifiedWhen DESC" - SelectNodesClassName="cms.article" TransformationName="cms.article.rssitem" SelectedItemTransformationName="cms.article.rssitem" SelectNodesPath="/%" SelectNodesWhere="" |
4. | Add the same line of code as used in the rss.aspx.cs code behind file (Response.ContentType = "text/xml") to articles_rss.aspx.cs. |
5. | Create the trasformation cms.article.rssitem like this in Site Manager -> Development -> Document Types -> ... edit Article ... -> Transformations: |
<item> <guid isPermaLink="true"><![CDATA[<%# GetAbsoluteUrl(GetDocumentUrl()) %>]]></guid> <title><![CDATA[<%# Eval("ArticleTitle") %>]]></title> <description><![CDATA[<%# Eval("ArticleText") %>]]></description> <pubDate><%# Convert.ToDateTime(Eval("DocumentModifiedWhen")).ToString("r") %></pubDate> <link><![CDATA[<%# GetAbsoluteUrl(GetDocumentUrl()) %>]]></link> </item> |
This code renders the particular items.
Page url: http://devnet.kentico.com/docs/devguide/index.html?setting_up_an_rss_feed.htm