Create an RSS Reader application

Spread the love

The September is ending and those last days of Summer re starting to fade away even here in Greece, so I hope you are ready for more interesting articles. This tutorial is actually a side-project for another tutorial I started that is coming up soon, but I thought it will be useful to have the code standalone. In this RSS Reader console application, we are going to see how to get and show RSS Feeds from code.

Prerequisites

  • Visual Studio 2017 or later
  • The System.ServiceModel.Syndication NuGet package

RSS Reader Code

We will be using the System.ServiceModel.Syndication to retrieve te RSS Feeds. The code is pretty straight forward. Replace the URL with the RSS Feed URL of your choice and that’s it! You have retrieved the RSS feed of your choice.

class Program
  {
      static void Main(string[] args)
      {
          string url = "https://azurecomcdn.azureedge.net/en-in/blog/topics/cognitive-services/feed/";
          XmlReader reader = XmlReader.Create(url);
          SyndicationFeed feed = SyndicationFeed.Load(reader);
          reader.Close();
          foreach (SyndicationItem item in feed.Items)
          {
              String subject = item.Title.Text;
              String summary = item.Summary.Text;
              String link = item.Links.FirstOrDefault().Uri.ToString();
              String date = item.PublishDate.ToString("dd/MM/yyyy");

              Console.WriteLine("*"+subject+"*");
              Console.WriteLine("    " + link);
              Console.WriteLine("    " + date);
              Console.WriteLine("    " + summary);
              Console.WriteLine();
          }

          Console.ReadLine();

      }
  }

The result shows up as follows:

You can find the complete code in this Github Repository.

 

Leave a Reply

Your email address will not be published. Required fields are marked *