Home > Asp.Net, Atom Feed, C#, RSS > Create RSS 2.0 and Atom 1.0 in Asp.Net 3.5 C#

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

  1. Sik
    May 26, 2010 at 12:05 am | #1

    This article is more benefit for me. Hope you post more benefit article in the future. ++

  2. Kian
    June 7, 2010 at 12:27 am | #2

    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 :)

  3. shawn
    August 2, 2010 at 9:11 pm | #3

    Perfect. This is exactly what I was looking for.

    Thanks,

  4. Daoud Dajani
    October 12, 2010 at 7:32 am | #4

    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 ?

    • October 19, 2010 at 10:19 am | #5

      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

  5. May 31, 2011 at 12:06 pm | #6

    Thanks a lot for solving one of my major problems.

  6. ash
    March 6, 2012 at 2:27 am | #7

    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

  1. March 5, 2012 at 2:34 pm | #1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 37 other followers