Kentico CMS 6.0 Developer's Guide

Creating RSS feed pages manually (obsolete)

Creating RSS feed pages manually (obsolete)

Previous topic Next topic Mail us feedback on this topic!  

Creating RSS feed pages manually (obsolete)

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

Due to backward compatibility with Kentico CMS versions prior to 5.5, it is also possible to create a dedicated page with an RSS feed. This way of creating RSS feeds is obsolete now, as syndication web parts provide a much more convenient way of creating RSS feeds.

 

The default installation contains a simple CMSPages\NewsRss.aspx page which 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 code example shows the code of the NewsRss.aspx page.

 

Please note: If you installed the Kentico CMS project as a web application, you need to rename the CodeFile property on the first line to Codebehind for the code example to be functional.

 

<%@ 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 an RSS feed page 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 NewsRss.aspx file except for the <%@ Page %> directive.

 

3.Change the following properties of the CMSRepeater control:

 

OrderBy: DocumentModifiedWhen DESC

ClassName: cms.article

TransformationName: cms.article.rssitem

SelectedItemTransformationName: cms.article.rssitem

Path: /%

WhereCondition: leave empty

 

4.Add the same line of code as used in the NewsRss.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.