Creating RSS Feeds Using ASP.Net

Warning: This is one of those late to the party posts where I show off some cool thing that everyone already likely knows about. I just feel special right now because I was able to push out something we’ve wanted to do for quite some time in an afternoon.


We wanted to have an RSS feed so customers could keep up to date with new or recently updated Dovetail Knowledge Base articles. My personal mental gate was that I really didn’t want to try to figure out how to properly create an RSS or Atom feed and I didn’t want to bother with complex heavy handed frameworks like Argotic. Then one day Joshintroduced me to the System.ServiceModel.Syndication namespace (introduced in .Net 3.5) and my life was never the same.


Simple stuff really. Create a SyndicatedFeed filled with feed items and hand that to a Feed Formatter.

Generating an RSS feed


public void ProcessRequest(HttpContext context)
    SyndicationFeed feed = CreateRecentSolutionsFeed();

    var output = new StringWriter();
    var writer = new XmlTextWriter(output);

    new Rss20FeedFormatter(feed).WriteTo(writer);

    context.Response.ContentType = "application/rss+xml";


But I get ahead of myself. We have to serve this feed from somewhere. Not really being an ASP.Net expert Josh got me started with a Generic Handler.



Which seems a thin construct for simply spiting content out of a URL. Perfect.

A Syndication Feed


To build the syndication I created this little helper method.

private static SyndicationFeed CreateRecentSolutionsFeed()
    var syndicationItems = GetRecentOrModifiedSolutionSyndicationItems(TimeSpan.FromDays(30));

    return new SyndicationFeed(syndicationItems)
                   Title = new TextSyndicationContent("Dovetail Software Knowledge Base"),
                   Description = new TextSyndicationContent("Recently created or modified solutions regarding products offered by Dovetail Software."),
                   ImageUrl = new Uri("")
Assembling a Syndication Item


I’ll skip the gory Dovetail SDK data access code that goes out to the Clarify database and materializes *poof* any solutions that have been created or modified in the last 30 days. Unless, of course, one of my 2 readers asks nicely for it. The interesting bit in any case is that it basically loops over all the solutions found and assembles a Syndication Item for each one.


private static SyndicationItem AssembleSolutionSyndicationItem(ClarifyDataRow solution)
    var id = solution["id_number"].ToString();
    var title = String.Format("[{0}] {1}", id, solution["title"]);
    var content = solution["description"].ToString();
    var url = new Uri(String.Format("{0}.aspx", id));

    return new SyndicationItem(title, null, url) { Summary = new TextSyndicationContent(content) };


The end result is a totally hard coded HTTP Handler generating an hopefully useful RSS feed for Dovetail’s customers.


Dovetail KB feed


Next up was to add a meta link to the feed in the html header of our knowledgebase pages. This makes the little RSS icon shows in the address bar of honest and decent hard working web browsers.


link rel="alternate" type="application/rss+xml" href="/resources/knowledgeBaseFed.ashx" title="Dovetail Knowledgebase Feed"/