How we can consume/read RSS of a site in asp.net
Introduction
In this article I am going to explain what is RSS and how we can consume/read RSS of a site in our website using asp.net.
Here we will cover following topics
1) whats is RSS
2) How it can helps us
3) How we can consume/read RSS in our application in asp.net
What is RSS
RSS, short form of "Really Simple Syndication". It is a way to easily distribute/publish updated works such as list of headlines, update notices, and blog entries to a wide number of people in a standardized format. These RSS feed are then used by computer programs that organize those headlines for easy reading.
How it helps us
Many people are interested in some website where the contents of the website changes regularly. for example community site, weblogs, health care, job portals and news sites. Using RSS of these sites you can easily stay informed by retrieving the latest content from these sites. You will save time by not visiting each site individually also you need not to join each site's email newsletter to get the latest content from these sites.
How we can consume/read RSS in our application in asp.net
Now if someone is interesred in latest articles published in www.dotnetlogix.com or any other site, he can simply integrate dotnetlogix.com RSS feed in his website and will be get informed without visiting dotnetlogix.com or the site he is interested in.
Here I will show you how you can consume/read and integrate RSS feed of dotnetlogix.com in your website.
In the below image you can see the RSS from www.dotnetlogix.com.
When you right click on this page you will get xml code as RSS feed is an XML file.
<rss version="2.0">
<channel>
<title>DotNetLogix Latest Articles</title>
<link>http://www.dotnetlogix.com/
<description>Latest Articles From DotNetLogix</description>
<copyright>Copyright © DotNetLogix, 2010-2011</copyright>
<language>en-us</language>
<webmaster>info@dotnetlogix.com</webmaster>
<lastbuilddate>10/16/2011 12:00:21 PM</lastbuilddate>
<ttl>30</ttl>
<item>
<title>Creating a Breadcrumb like Menu using CSS and JQuery</title>
<link>http://www.dotnetlogix.com/Article/HTML/184/Creating-a-Breadcrumb-like-Menu-using-CSS-and-JQuery.html
<description>Creating a Breadcrumb like Menu using CSS and JQuery</description>
<author>Najmul Hoda</author>
<pubdate>Sun, 02 Oct 2011 11:32:18 GMT</pubdate>
</item>
<item>
<title>Take Backup of a DataBase By Coding</title>
<link>http://www.dotnetlogix.com/Article/sqlserver/183/Take-Backup-of-a-DataBase-By-Coding.html
<description>In this article I am going to show how we can show all Data Server in a network and on selecting a Data Server.</description>
<author>Rahul Saxena</author>
<pubdate>Sun, 02 Oct 2011 00:59:53 GMT</pubdate>
</item>
<item>
<title>Replicate function in Sql Server</title>
<link>http://www.dotnetlogix.com/Codesnippet/sqlserver/181/Replicate-function-in-Sql-Server.html
<description>Replicate fucntion in Sql server repeats a string for a number of times specified by the user.</description>
<author>Najmul Hoda</author>
<pubdate>Tue, 27 Sep 2011 12:24:41 GMT</pubdate>
</item>
</channel>
</rss>
In the above XML file we need only item tags and tags inside it. Now lets integrate RSS feed in our web application
Step1 . Create a new page called readRSSFeed.aspx
Step2 . Drag and drop XMLDatasource data control from toolbar to aspx page and configure the propertise of the XMLDataSource as below.
<asp:xmldatasource id="XmlDataSource1" datafile="http://www.dotnetlogix.com/RSS.xml" runat="server">
</asp:xmldatasource>
Step3 . Now to show RSS feed in proper format we can use different DataSources such as GridView, Repeater, ListView, DataList. For our example we will use ListView.
I am declaring here a ListView to show RSS data and formating it to show data in proper format.
<div>
<b>Latest Articles From DotNetLogix </b>
</div>
<div>
<asp:listview id="lstViewRSSFeed" datasourceid="XmlDataSource1" runat="server">
<itemtemplate>
<div style="background-color: rgb(204, 204, 204); font-size: 12px; border: 1px solid black; padding: 5px;">
<div>
<b>Title :</b>
<%#XPath("title")%>
</div>
<div>
<b>Url:</b> <a href='<%#XPath("link")%>' > <%#XPath("link")%>
</a>
</div>
<div>
<b>Desc: </b>
<%#XPath("description")%>
</div>
<div>
<b>Author :</b>
<%#XPath("Author")%>
</div>
</div>
</itemtemplate>
</asp:listview>
</div>
Step4. Now run the page we you get something like below image.
When you run, in the webpage you will see 20 articles. If you want to limit the list of items to 5 or 10 then you can set that limit in the XMLDataSource like below
<asp:xmldatasource runat="server" xpath="rss/channel/item [position()<=5]" datafile="http://www.dotnetlogix.com/RSS.xml" id="XmlDataSource1">
</asp:xmldatasource>
In the above code you can see I have set XPath value to "rss/channel/item [position()<=5]". It tells the XMLDatasource to get top 5 items from the list.
Hope it will help you. Stay connected for more....
Now I am going in compilation mode...................... Happy Reading.......