Efficiently Read RSS Feeds using .NET Core: A Step-by-Step Guide for Building a Simple Console Application

Many websites and blogs have their content available via feeds that users and applications can subscribe to. Feeds basically are a simplified version of the site content, providing text and media –only representation of the data published on the website. One of the most popular feed formats is RSS and it stands for Really Simple Syndication. It is an XML-based format of the content and is used by the majority of websites that contain dynamically updated content, like blogs or news resources.

In this post, we will develop a simple console application to read RSS feeds with .NET Core.

Let's start by creating the console application with .NET Core:

  • Open Visual Studio. In this post, we are using Visual Studio 2022 Community Version

Reading RSS Feeds with .NET Core Console App - Step-1, read rss feed, feed reader, read rss, rss reader windows, rss free reader, best feed reader, desktop rss reader

  • Set the project name as "ReadRSSFeeds"

Reading RSS Feeds with .NET Core Console App - Step-2

  • In the additional information, select .NET 6 for the framework

Reading RSS Feeds with .NET Core Console App - Step-3

Now, we have the console application ready with .NET 6. The next step is to install the package "System.ServiceModel.Syndication". This package provides classes related to service model syndication. Run this syntax in the Package Manager Console
Install-Package System.ServiceModel.Syndication -Version 6.0.0

Installal Package - System.ServiceModel.Syndication

Once the package is installed, we need to make use of the using statement to add a reference to the Syndication namespace here is the syntax:

using System.ServiceModel.Syndication;

Now we need to right the main code to read and process the feeds, here is the C# syntax:

var url = "https://jamilhallal.blogspot.com/feeds/posts/default?alt=rss";
using var reader = XmlReader.Create(url);
var feed = SyndicationFeed.Load(reader);

Once the feed loaded, we can query each syndicated item as per the following code which will return the most recent published post in the blog:

var post = feed.Items.FirstOrDefault();
Here are the main properties that we can access from each instance of a Syndication Item:
  • Authors
  • Categories
  • Content
  • Contributors
  • Copyright
  • Publish Date
  • Links

Here is the final code in the class "Program.cs" of the .NET Core Console app:

// See https://aka.ms/new-console-template for more information
using System.Xml;
using System.ServiceModel.Syndication;

var url = "https://jamilhallal.blogspot.com/feeds/posts/default?alt=rss";
using var reader = XmlReader.Create(url);
var feed = SyndicationFeed.Load(reader);
var post = feed.Items.FirstOrDefault();
//Now, post represent the most recent published post in the blog. 

2 Comments

  1. Hi, I am getting a weird error when getting the rss from http://feeds.foxnews.com/foxnews/latest. It looks like it is coming with some bad chars but the SyndicationFeed.Load(reader) fails and it cannot download anything. Did you have this problem with some other RSS? So far I cannot find an answer.
    Thanks

    ReplyDelete
    Replies
    1. Hey, no I didn't face similar issue. what is the error you are receiving?

      Delete
Previous Post Next Post