In the .NET 3.5 framework there is a namespace titled System.ServiceModel.Syndication which very few people seem to know about. The classes contained in this library allows you to create and consume RSS feeds with minimal effort. I recently created a feed for my WeBlog application. I was astonished about how little time it took to implement an RSS Feed. Instead of weighing you down with all the details...I'll let the code do the talking:
public ActionResult Feed( int? page, int? pageSize ) {
var query = from x in Engine.Posts.FindPosts( page, pageSize )
where
x.PublishDate != null
orderby
x.PublishDate descending
select x;
List<PostModel> posts = query.ToList();
Uri site = new Uri(Engine.GetWebAppRoot());
SyndicationFeed feed = new SyndicationFeed(Engine.Settings.SiteName, Engine.Settings.SiteDescription, site );
List<SyndicationItem> items = new List<SyndicationItem>();
foreach( PostModel post in posts ) {
SyndicationItem item = new SyndicationItem(post.Title, post.Content,
new Uri( Engine.GetWebAppRoot() + "/Posts/" + post.Slug), post.ID.ToString(), post.PublishDate ?? DateTime.Now);
items.Add(item);
}
feed.Items = items;
return new Core.RSSActionResult() { Feed = feed };
}
Read more: Code Capers