Before moving to actual implementation of RSS feed, we
will understand the format of RSS feeds that a RSS reader can understand.
For example, CodeDigest RSS feed will look like,
<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0">
<channel>
<title>CodeDigest.com Latest Articles</title>
<link>http://www.codedigest.com</link>
<description>Latest articles hosted on
CodeDigest.com.</description>
<item>
<title>Useful Datagrid Tips</title>
<description>There are some frequent queries that
are being asked in most of the forums and UG’s regarding datagrid. I have
compiled a list of useful tips from my previous posts and posted it
here.</description>
<link>http://www.codedigest.com/Articles/ASPNET/77_Useful_Datagrid_Tips.aspx</link>
<pubDate>4/29/2008 9:47:12 AM</pubDate>
</item>
</channel>
</rss>
As we can see the above XML, the whole contents are
packed inside <rss> tag followed by <channel> tag. And the actual
information about the posts are kept inside <item> tag which in turn is
packed inside a <channel> tag. Read the history of RSS here and specification of
RSS here.
To construct RSS feed; we need to form the above xml for the frequently
updated data and emit it. In this article, we will use Repeater and SqlDataSource
control to construct the RSS XML and emit it.
Steps
1. Open Visual Studio 2005.
2. Select File>New>Website.
Select ASP.Net Website and provide a name for your project.
3. Select a language of your
choice, I have selected C#. Click OK.
4. Drag a Repeater control and
SqlDataSource control from Data tab of the Visual Studio toolbox.
5. Configure the SqlDataSource
control to select the required data for constructing RSS feed. For easy
understanding, I have a created a Sql Express database with a table "Articles" in
App_Data folder of the sample project.
6. Configure the DataSourceID of
the Repeater control to SqlDataSource control’s ID. Refer the below code,
|