Click here to Skip to main content
15,747,766 members
Articles / Web Development / ASP.NET
Posted 10 Jun 2015


3 bookmarked

Consume an Atom Feed in an ASP.NET Web Page

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
10 Jun 2015CPOL2 min read
Consuming / displaying an Atom feed on an ASP.NET web page


Following on from my previous article on consuming an RSS feed, I recently had a requirement to display the contents from an Atom feed on a web page. In fact this was to display the contents of my very own Github activity feed on my web site.

I won't compare and contrast RSS with Atom in this article. There are plenty of sources out there that have alredy done that.

Displaying an Atom feed on a web site is relatively simple. In its simplest terms an Atom feed is an XML structure that contains data which can be displayed on a web page. Atom feeds are used by many different kinds of web sites to push information. Users who are interested in that information can then subscribe to those Atom feeds by consuming them.

Structure of an Atom feed

Atom feeds have the following basic structure. Other information is contained within them but for the purposes of brevity these have been removed.

<feed xmlns="">
	<title>Example Feed</title>
	<subtitle>A subtitle.</subtitle>
	<link href="" rel="self" />
	<link href="" />
		<title>My Atom feed</title>
		<link href="" />
		<link rel="alternate" type="text/html" href=""/>
		<link rel="edit" href=""/>
		<summary>Some summary text.</summary>
		<content type="xhtml">
			<div xmlns="">
				<p>This is the entry content in HTML format.</p>
			<name>Dominic Burford</name>

The information that I was interested in for my web site were the Title, Description and Publication Date items from the Atom feed.

Consuming an Atom feed

There are several different ways to achieve this, so this is just one way. I have implemented this using an ASP.NET web form but the general principle can be applied to other technologies.

  1. Firstly I added a Gridview control to my web page. A Repeater control is also perfectly acceptable,
    <asp:GridView ID="gvAtom" runat="server">
            <table width="100%" border="0" cellpadding="0" cellspacing="5">
                <h3 style="color:#3E7CFF"><%#Eval("Title") %></h3>
                <%#Eval("PublishDate") %>
                <td colspan="2">
                  <hr />
                  <%#Eval("Description") %>
  2. In the code behind I have added a new method to populate the Gridview control with data from the Atom feed as follows.
    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Globalization;
    using System.Linq;
    using System.Xml.Linq;
    using System.ServiceModel.Syndication;
    using System.Xml;
    protected void Page_Load(object sender, EventArgs e)
    private void PopulateAtomFeed()
        string atomFeedUrl = ConfigurationManager.AppSettings["AtomFeedUrl"];
        List<Feeds> feeds = new List<Feeds>();
        XmlTextReader reader = new XmlTextReader(atomFeedUrl);
        SyndicationFeed feed = SyndicationFeed.Load(reader);
        if (feed != null)
            feeds.AddRange(feed.Items.Select(i => new Feeds
                Title = i.Title.Text,
                PublishDate = i.PublishDate.DateTime.ToUniversalTime().ToString(CultureInfo.InvariantCulture),
                Description = ((TextSyndicationContent)(i.Content)).Text
        gvAtom.DataSource = feeds;
  3. I then created a simple POCO Feed class that mapped the Atom feed items to the Gridview control.
    public class Feeds
        public string Title { get; set; }
        public string PublishDate { get; set; }
        public string Description { get; set; }
  4. I store the URL to my Atom feed in the web.config. This ensures that the URL can be easily changed if necessary.
      <add key="AtomFeedUrl" value=""/>


And that's all there is to it. As can be seen from the link I provided you can view the Atom feed yourself on my web site.

If you are likely to display multiple Atom feeds then you can easily create a User Control and add the Gridview to this. To make the User Control reusable you could add a public property to the User Control to set the Atom feed URL. You then add the User Control to your web page and set the Atom feed URL property as required.

Hopefully this article has given you sufficient information for you to start consuming Atom feeds in your own applications. Feel free to leave a comment if you would like me to further elaborate on anything within this article.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Technical Lead Gold-Vision CRM
United Kingdom United Kingdom
I am a professional software engineer and technical architect with over twenty years commercial development experience with a strong focus on the design and development of web and mobile applications.

I have experience of architecting scalable, distributed, high volume web applications that are accessible from multiple devices due to their responsive web design, including architecting enterprise service-oriented solutions. I have also developed enterprise mobile applications using Xamarin and Telerik Platform.

I have extensive experience using .NET, ASP.NET, Windows and Web Services, WCF, SQL Server, LINQ and other Microsoft technologies. I am also familiar with HTML, Bootstrap, Javascript (inc. JQuery and Node.js), CSS, XML, JSON, Apache Cordova, KendoUI and many other web and mobile related technologies.

I am enthusiastic about Continuous Integration, Continuous Delivery and Application Life-cycle Management having configured such environments using CruiseControl.NET, TeamCity and Team Foundation Services. I enjoy working in Agile and Test Driven Development (TDD) environments.

Outside of work I have two beautiful daughters. I am also an avid cyclist who enjoys reading, listening to music and travelling.

Comments and Discussions

-- There are no messages in this forum --