Create RSS 2.0 and Atom 1.0 in Asp.Net 3.5 C#
In this article I am going to explain how we can create web syndications like RSS 2.0 and Atom 1.0 in Asp.Net and C# with very minimal code. (You can download the entire article from here ).
RSS 2.0
Really Simple Syndication (RSS) is one of the syndication feed formats which can get the frequently updated content from the web site. (Refer: http://en.wikipedia.org/wiki/RSS).
The specification of RSS format http://cyber.law.harvard.edu/rss/rss.html. RSS is most widely used syndication format.
Atom 1.0
Atom is a syndication format which is more flexible than RSS. Atom came into existence out of a need to improve RSS. (Refer: http://en.wikipedia.org/wiki/Atom_standardard)
In Asp.Net 3.5 frame work we can create subscription feeds with very minimal code using System.ServiceModel.Syndication namespace which contains all of the classes that make up the Syndication Object Model. For example below is a sample Blog class I am defining a public method and some properties to retrieve the blog items (I have hardcoded two items you can replace this from your database logic).
The next step I am going to create another class called Syndication Helper which converts our web content to syndication format.
Code Explanation
Uri uri = new Uri(“http://deepumi.wordpress.com”);
Configure your site url ( blog or news).
SyndicationFeed syndicationFeed = new SyndicationFeed();
Syndicaiton Feed class represent a top level of feed object, (you can add your blog name / site name with description and the last blog/site updated time).
List<SyndicationItem> items = new List<SyndicationItem>();
Syndication Item class represent a individual feed atom/rss.item object like item url, item description, item id, last updated etc. Here I am creating a syndicaiton item collection object which mapping from MyBlogList() method.
List<Blog> oBlogList = Blog.GetMyBlogList();
foreach (Blog oBlog in oBlogList)
{
SyndicationItem oItem = new SyndicationItem(oBlog.Title,
SyndicationContent.CreateHtmlContent(oBlog.Description),
new Uri(oBlog.Url),
oBlog.BlogId.ToString(),
oBlog.LastUpdated);
items.Add(oItem);
}
Finally you are return the SyndicationFeed object to the aspx pages.
Now we need to render the atom and rss content in the aspx pages.
Create a new aspx page called rss.aspx and make sure there is no html markup in the page(just a blank page)
<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”rss.aspx.cs” Inherits=”rss” %>
Code behind (RSS page)
Create a new aspx page called rss.aspx and make sure there is no html markup in the page(just a blank page)
<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”atom.aspx.cs” Inherits=”atom” %>
Code behind (Atom page)
Hope this help and If you have any comments, please feel free to write your feedback.
You can download the entire article from here or copy paste this URL
http://www.4shared.com/file/240764190/b37e055d/Feeds.html
Thanks
Deepu






This article is more benefit for me. Hope you post more benefit article in the future. ++
Thanks, it is a great article. I was googling to find a article about rss and atom, finally, I found this great article
I am going to use your instructions tomorrow (it’s 5 AM now!)
Thanks again
Perfect. This is exactly what I was looking for.
Thanks,
Thank you for this greate article, can you explain how can i add images to my rss feed? so that they can be seen on the left of each feed entery ?
Yes it is possible if you want to add image by using SyndicationContent.CreateHtmlContent
SyndicationItem item = new SyndicationItem(“title”, SyndicationContent.CreateHtmlContent(“
“), new Uri(“http://google.com”),”itemId”,DateTime.Now);
Hope this helps
Thanks
Deepu
Thanks a lot for solving one of my major problems.
Hi Deepu,
Thanks for this wonderful article. Just one thing, I am curios about, is there any way we can find out whether it is atom feed or rss feed. I would like to use only one ashx and in that I would like to instantiate class based on its type.
Thanks