Today we are learn how to retrieve an RSS feed into a Windows 8 Apps. This article shows how to read a RSS feed and display it with an interactive user interface into your Metro App.
We are trying to get the RSS feed of C-sharpcorner.com and display the title of each article with their pub date and also content from the latest article to be displayed in the Metro app.
So, let's begin creating a Windows 8 Apps that shows the full text of the posts in both RSS and Atom form.
Step 1: First of all we need to create some business classes that hold the RSS feed data, so that we can retrieve from there as required.
To add a new class file to a project:
Select Project > Add Class. The New Item dialog box opens.
Enter a name for the class file. In this example we use FeedData.
Click Add. Your new class file is created.
The Feeddata class holds the data about the RSS feed. It has some properties that contain info about the individual articles such title, pubdate, author name etc. It also has a collection of feeds and a method to retrieve the feeds from the network.
Here is code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace rss
{
public class FeedData
{
private List<FeedItem> _Items = new List<FeedItem>();
public List<FeedItem> Items
{
get
{
return this._Items;
}
}
}
public class FeedItem
{
public string Title { get; set; }
public string Author { get; set; }
public string Content { get; set; }
public DateTime PubDate { get; set; }
public Uri Link { get; set; }
}
}
Step 2: Add the following namespace in the mainPage.xaml.cs file:
using Windows.Web.Syndication;
Step 3: Now we have to retrieve the RSS feed data. Here we use the SyndicationClient class that retrieves a fully parsed RSS feed, so we can use the data without worrying about parsing XML.
Here is the code for getting RSS feeds:
private async void k_Click_1(object sender, RoutedEventArgs e)
{
SyndicationClient client = new SyndicationClient();
Uri feedUri = new Uri("http://www.c-sharpcorner.com/RSS/TopArticles.aspx");
feed = await client.RetrieveFeedAsync(feedUri);
FeedData feedData = new FeedData();
foreach (SyndicationItem item in feed.Items)
{
FeedItem feedItem = new FeedItem();
feedItem.Title = item.Title.Text;
feedItem.PubDate = item.PublishedDate.DateTime;
feedItem.Author = item.Authors[0].Name;
// Handle the differences between RSS and Atom feeds.
if (feed.SourceFormat == SyndicationFormat.Atom10)
{
feedItem.Content = item.Content.Text;
feedItem.Link = new Uri("http://www.c-sharpcorner.com" + item.Id);
}
else if (feed.SourceFormat == SyndicationFormat.Rss20)
{
feedItem.Content = item.Summary.Text;
feedItem.Link = item.Links[0].Uri;
}
feedData.Items.Add(feedItem);
}
ItemListView.DataContext = feedData.Items;



iram jabeenPosted Aug 27, 2015, 8:34 AM
Great Article...I love it
Ankesh RajPosted May 1, 2014, 4:37 AM
We need to do some changes in MainPage.xaml.cs 1. Try This Code::::: SyndicationClient client = new SyndicationClient(); Uri feedUri = new Uri("http://www.c-sharpcorner.com/RSS/TopArticles.aspx"); SyndicationFeed feed = await client.RetrieveFeedAsync(feedUri); FeedData feedData = new FeedData(); foreach (SyndicationItem item in feed.Items) {......................... .............................. Instead of::::::::: SyndicationClient client = new SyndicationClient(); Uri feedUri = new Uri("http://www.c-sharpcorner.com/RSS/TopArticles.aspx"); feed = await client.RetrieveFeedAsync(feedUri); FeedData feedData = new FeedData(); foreach (SyndicationItem item in feed.Items) {............................. ............................. 2. Try this code :::: private void ItemListView_SelectionChanged(object sender, SelectionChangedEventArgs e) { Selector Links = sender as Selector; FeedItem selectedItem = Links.SelectedItem as FeedItem; web.Navigate(selectedItem.Link); web.Visibility = Visibility.Visible; } Instead of:::: private void ItemListView_SelectionChanged(object sender, SelectionChangedEventArgs e) { FeedItem f = new FeedItem(); f.Link = feed.Items[ItemListView.SelectedIndex].Links[0].Uri; web.Navigate(selectedItem.Link); web.Visibility = Visibility.Visible; } For More Help Contact me at [email protected]
Sudhir GoswamiPosted Jan 6, 2014, 2:47 AM
Windows.Web.Syndication Where i can get it. I am using VS2012
gregory perozzoPosted May 26, 2013, 7:54 PM
Hello. In this line feed = await client.RetrieveFeedAsync(feedUri); , where is the declaration of "feed" variable?
MZeki OsmancikPosted Dec 1, 2012, 1:10 PM
i have a problem with this code. i cant read atom feeds from http://www.mzekiosmancik.com/feed/atom/ can you help me ?
Gaurav GuptaPosted Sep 4, 2012, 1:52 AM
What do you mean?
goe sfwePosted Aug 31, 2012, 1:01 PM
this article is missing a lot :(