RSS Feed reading using ASP.NET with C#.Net|RSS Feed reading with proxy set up

We can read RSS feeds using ASP.NET with C# code. In the below example, if you click on button all rss feed data will read and display on the webpage. In the corporate network we are unable to read RSS feeds with out using proxy. Please give your proxy name in the below line. Basically, this proxy programming required in the corporate networks.  That's it entire code will work.

WebProxy proxyObject = new WebProxy("http://proxyName:8080/", true);

Output page:

.aspx Code
<head runat="server">
    <form id="form1" runat="server">
        <table cellpadding="0" cellspacing="0">
                    <asp:Table ID="table1" runat="server">
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />


C# Code behind. 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.IO;

public partial class _Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)

    protected void Button1_Click(object sender, EventArgs e)
        //int proxyValue = 8080;

        WebProxy proxyObject = new WebProxy("http://proxyName:8080/", true);
        proxyObject.Credentials = CredentialCache.DefaultCredentials;

        WebRequest MyRssRequest = WebRequest.Create("");
        MyRssRequest.Proxy = proxyObject;
        WebResponse MyRssResponse = MyRssRequest.GetResponse();
        Stream MyRssStream = MyRssResponse.GetResponseStream();
        //Here we are loading previously created xml document. 
        XmlDocument MyRssDocument = new XmlDocument();
        XmlNodeList MyRssList = MyRssDocument.SelectNodes("rss/channel/item");

        string sTitle = "";
        string sLink = "";
        string sDescription = "";
        // Iterate/Loop through RSS Feed items
        for (int i = 0; i < MyRssList.Count; i++)
            XmlNode MyRssDetail;
            MyRssDetail = MyRssList.Item(i).SelectSingleNode("title");
            if (MyRssDetail != null)
                sTitle = MyRssDetail.InnerText;
                sTitle = "";
            MyRssDetail = MyRssList.Item(i).SelectSingleNode("link");
            if (MyRssDetail != null)
                sLink = MyRssDetail.InnerText;
                sLink = "";
            MyRssDetail = MyRssList.Item(i).SelectSingleNode("description");
            if (MyRssDetail != null)
                sDescription = MyRssDetail.InnerText;
                sDescription = "";

            TableCell block = new TableCell();
            block.Text = "<span style='font-weight:bold'><a href='" + sLink + "' target='new'>" + sTitle + "</a></span>";
            TableRow row = new TableRow();

            TableCell block_description = new TableCell();
            block_description.Text = "<p align='justify'>" + sDescription + "</p>";
            //TableRow row2 = new TableRow();


Share this post :

Post a Comment

Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.

Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar