RSS Feed with the Syndication Class
By Peter Bromberg
The System.ServiceModel.Syndication namespace provides classes designed to create and consume RSS feeds. Here's a simple demo page that consumes and displays our Eggheadcafe.com Articles feed.
<%@ Page Title="Feed Reader" Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.ServiceModel.Syndication" %>
<script language="C#" runat='server'>
protected void Page_Load(object sender, EventArgs e)
{
XmlReader reader = XmlReader.Create("http://www.eggheadcafe.com/rss.xml");
Rss20FeedFormatter formatter =new Rss20FeedFormatter();
formatter.ReadFrom(reader);
reader.Close();
Label3.Text = formatter.Feed.Title.Text;
DataList1.DataSource =formatter.Feed.Items;
DataList1.DataBind();
}
</script>
<b> <asp:Label id=Label3 runat=server></asp:Label> </b> <Br />
<asp:datalist id="DataList1" runat="server" Width="650px"
BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px"
CellPadding="2" ForeColor="Black">
<AlternatingItemStyle BackColor="PaleGoldenrod" />
<FooterStyle BackColor="Tan" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server"
Text='<%# Eval("Title.Text") %>'
Font-Bold="True"
NavigateUrl='<%# Eval("Links[0].Uri.AbsoluteUri") %>'>
</asp:HyperLink>
<br />
<asp:Label ID="Label1" runat="server"
Text='<%# Eval("Summary.Text") %>'>
</asp:Label>
<br />
<asp:Label ID="Label2" runat="server" Font-Bold="True"
Text='<%# Eval("PublishDate.DateTime","Published On :{0}") %>'>
</asp:Label>
</ItemTemplate>
<SelectedItemStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
</asp:datalist>
The above is a self-contained, "script-only" page that does everything.
You can view the live page in action here.
RSS Feed with the Syndication Class (15841 Views)