ASP.NET RSS Feeds Display | Get

In this article, I will show you, How to display RSS feeds on your website. Actually, RSS feeds is an XML file. In ASP.NET we can create it easily through generic handlers. By using XmlTextWriter class, we can create XML file and XmlTextReader class we can read XML file. In this article, I will use XmlTextReader class to read it.


Complete Source Code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ReadRss.aspx.cs" Inherits="ReadRss" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Read Rss" OnClick="Button1_Click" Width="163px" />
    </div>
        <asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
                <table>
                    <tr>
                        <td>
                            <asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("Title")%>'/>


                        </td>
                    </tr>
                     <tr>
                        <td>
                            <asp:Label ID="Label1" runat="server" Text='<%# Eval("Description") %>'/>


                        </td>
                    </tr>
                </table>


            </ItemTemplate>
        </asp:Repeater>
    </form>
</body>
</html>

CodeBehind File

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

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

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        WebRequest request = WebRequest.Create("http://localhost:11973/Handler.ashx");
        WebProxy proxy = new WebProxy("http://localhost:11973/Handler.ashx", true);
        request.Proxy = proxy;
        request.Timeout = 6000;
        try
        {
            WebResponse response = request.GetResponse();
            XmlTextReader xmlreader = new XmlTextReader(response.GetResponseStream());
            DataSet ds = new DataSet();
            ds.ReadXml(xmlreader);
            Repeater1.DataSource = ds.Tables[2];
            Repeater1.DataBind();
        }
       catch(Exception ex)
        {
            throw ex;
        }
    }
}
ASP.NET RSS Feeds Display | Get ASP.NET RSS Feeds Display | Get Reviewed by Jacob Lefore on December 29, 2015 Rating: 5

No comments