RSS Feed Reader

|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class test_special_rssreader : System.Web.UI.Page
{

	public void ProcessRSSItem(string rssURL)
	{

		string rowcolor = "#ffffff";

		System.Net.WebRequest myRequest = System.Net.WebRequest.Create(rssURL);
		System.Net.WebResponse myResponse = myRequest.GetResponse();

		System.IO.Stream rssStream = myResponse.GetResponseStream();
		System.Xml.XmlDocument rssDoc = new System.Xml.XmlDocument();
		rssDoc.Load(rssStream);

		System.Xml.XmlNodeList rssItems = rssDoc.SelectNodes("rss/channel");

		System.Xml.XmlNode rssDetail;

		string title = "";
		string link = "";
		string description = "";

		for (int i = 0; i < 1; i++)
		{
			//rssDetail = rssItems.Item

			rssDetail = rssItems.Item(0).SelectSingleNode("title");

			if (rssDetail != null)
			{
				title = rssDetail.InnerText;
				if (title.StartsWith((i + 1).ToString()))
					title.Insert(0, (i + 1).ToString());
			}

		}

		rssItems = rssDoc.SelectNodes("rss/channel/item");



		Response.Write("<table cellpadding='2' cellspacing='0' style='width:200px; border:1px solid #f68f16;'>");
		Response.Write("<tr style='background-color:#f68f16'><td><strong>" + title + "</strong></td></tr>");

		//for (int i = 0; i < rssItems.Count; i++)
		for (int i = 0; i < 10; i++)
		{

			rssDetail = rssItems.Item(i).SelectSingleNode("title");
			if (rssDetail != null)
			{
				title = rssDetail.InnerText;
				if (title.StartsWith((i + 1).ToString()))
					title.Insert(0, (i + 1).ToString());
			}


			rssDetail = rssItems.Item(i).SelectSingleNode("link");
			if (rssDetail != null)
			{
				link = rssDetail.InnerText;
			}


			rssDetail = rssItems.Item(i).SelectSingleNode("description");
			if (rssDetail != null)
			{
				description = rssDetail.InnerText;
			}


			title = title.Replace("#", "");
			title = title.Replace(":", ".");

			Response.Write("<tr style='background-color:" + rowcolor + "'><td>");
			Response.Write("<a target='_blank' style='color:#0000ff' href='" + link + "'>" + title + "</a>");
			Response.Write("</td></tr>");

			if (rowcolor == "#ffffff")
			{
				rowcolor = "#cccccc";
			}
			else
			{
				rowcolor = "#ffffff";
			}
		}

		Response.Write("</table>");
	}


	protected void Page_Load(object sender, EventArgs e)
	{
		string feedurl = Request.QueryString["url"];

		ProcessRSSItem(feedurl);

	}
}
Originally Posted on April 8, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.