Read Rss feed in c#

Posted: August 9, 2012 in, C#
Tags: , , , , ,

In this Article I am going to explain how you can read rss xml file into c# . It is very easy , you just have to follow few steps to catch xml feed into your code .

Here i`ll show you how can catch the rss feed , then you can display it on your website as you want .

to implement it you need to understand the function i am writing below :-

public void TestFeed()
var NewsRSS = XDocument.Load(“”); // to load XML file in variable
var rssItemsList = from d in NewsRSS.Descendants(“item”)
select d;
int count = rssItemsList.Count(); //get the count of feed items
foreach (var rssItem in rssItemsList)
XElement pubdate = rssItem.Descendants(“pubDate”).FirstOrDefault(); //to get the published date of news
string publishDate = string.Empty;
if (pubdate != null)
publishDate = pubdate.Value;
DateTime time = DateTime.Now;
string dayofWeek = time.DayOfWeek.ToString();
string dayofmonth = time.Month.ToString();
string year = time.Year.ToString();
string title = rssItem.Descendants(“title”).FirstOrDefault() == null ? string.Empty : rssItem.Descendants(“title”).FirstOrDefault().Value; //to set values in variable
string link = rssItem.Descendants(“link”).FirstOrDefault() == null ? string.Empty : rssItem.Descendants(“link”).FirstOrDefault().Value;//to set values in variable
string description = rssItem.Descendants(“description”).FirstOrDefault() == null ? string.Empty : rssItem.Descendants(“description”).FirstOrDefault().Value;
string guid = rssItem.Descendants(“guid”).FirstOrDefault() == null ? string.Empty : rssItem.Descendants(“guid”).FirstOrDefault().Value;//to set values in variable
string summarry = string.Empty;
if (!string.IsNullOrEmpty(description))
int length = description.Length;
if (length > 200)
summarry = description.Substring(0, 199) + “…”;
summarry = description;


This is just an example . Now You Can Play With It As you Want 😉

Hope This Post Will Help you Somehow . . 🙂

Waiting For Your Valuable Feedback.

  1. Hi there, I discovered your web site by means of Google whilst looking for a similar matter, your web site got here up, it appears good. I have added to my favourites|added to bookmarks.

  2. I just want to mention I’m newbie to weblog and absolutely loved you’re web site. Most likely I’m likely to bookmark your blog . You amazingly come with great articles and reviews. With thanks for revealing your webpage.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s