Responsive Ads Here

Friday, October 17, 2014

Simple way to Read RSS feed using c#

I came across a scenario to display the RSS feed in a visual web part. To access the RSS Feed initially we need to create a Http Request which will be used to retrieve the RSS feed.
Please find the below code snippet to bind the RSS feed to a simple repeater control.

 public void BindRSSFeed(string rssFeedUrl)
        {
            try
            {
                //create an http request which will be used to retrieve the rss feed
                HttpWebRequest rssFeed = (HttpWebRequest)WebRequest.Create(rssFeedUrl);
                //use a dataset to retrieve the rss feed
                DataSet rssData = new DataSet();
                //read the xml from the stream of the web request
                rssData.ReadXml(rssFeed.GetResponse().GetResponseStream());
                if (rssData != null && rssData.Tables["Item"].Rows.Count > 0)
                {
                    DataTable rssDataTable = rssData.Tables["Item"];
 rptrUpcomingRssEvents.DataSource = finalFiltereddt;
                        rptrUpcomingRssEvents.DataBind();
                }
            }
         }   
    

 Please find the below link for clear understanding.
http://heathesh.com/post/2010/05/10/A-simple-way-to-read-an-RSS-feed-using-C.aspx

No comments:

Post a Comment