RSS Feed Reader For Sitefinity4.4 Available?
Hi I am trying to find the RSS Feed Reader Add-on in the sitefinity market place but in vain to find it for Sitefinity 4.4. I tried with the earlier versions but not at all wroked out. Can any body suggest me how to develop a custom RSS Reader. can i achieve this functionality without relying on the external add-ons?? (means using sitefinity News module). Here i need a custom field to accept a Url and need Fetch the news from it. and also need to set the limit of the content displayed. Any suggestion are appreciated. Thanks in advance..
Hi Satya,
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="RSS.ascx.cs" Inherits="Custom_RSS" %><asp:PlaceHolder ID="phForm" runat="server"><div class="title"> <h2> <a href="#">News</a> </h2></div><asp:Repeater ID = "rssRepeater" runat = "server"><ItemTemplate> <table style="width:100%;font-family:Arial"> <tr> <td style=" font-weight:bold"> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl = '<%#Eval("link")%>' Target="_blank" Text = '<%#Eval("title")%>'></asp:HyperLink> </td> </tr> <tr> <td><hr /></td> </tr> <tr> <td style="background-color:#FFFFFF"> <asp:Label ID="Label1" runat="server" Text='<%#Eval("description")%>'></asp:Label> </td> </tr> </table> <br /></ItemTemplate></asp:Repeater></asp:PlaceHolder>using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Net.Configuration;using System.Text;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Text.RegularExpressions;using System;using System.Net;using System.Xml;using System.Data; public partial class Custom_RSS : System.Web.UI.UserControl public string RssFeedUrl get; set; public int NumberOfNewsItems get; set; public int WordsPerNewsItem get; set; protected void Page_Load(object sender, EventArgs e) if (!String.IsNullOrEmpty(RssFeedUrl)) rssRepeater.DataSource = GetTable(RssFeedUrl); rssRepeater.DataBind(); protected DataTable GetTable(string rssUrl) DataTable NewsTable = new DataTable(); try WebRequest request = WebRequest.Create(rssUrl); WebResponse response = request.GetResponse(); StringBuilder sb = new StringBuilder(""); Stream rssStream = response.GetResponseStream(); XmlDocument rssDoc = new XmlDocument(); rssDoc.Load(rssStream); XmlNodeList rssItems = rssDoc.SelectNodes("rss/channel/item"); NewsTable.Columns.Add(new DataColumn("Title", typeof (string))); NewsTable.Columns.Add(new DataColumn("Link", typeof (string))); NewsTable.Columns.Add(new DataColumn("Description", typeof (string))); int upperlimit = rssItems.Count; if (upperlimit > NumberOfNewsItems) upperlimit = NumberOfNewsItems; if (upperlimit > 0) for (int i = 0; i < upperlimit; i++) DataRow NewsTableRow = NewsTable.NewRow(); XmlNode rssDetail; rssDetail = rssItems.Item(i).SelectSingleNode("title"); NewsTableRow["Title"] = rssDetail != null ? rssDetail.InnerText : ""; NewsTableRow["Link"] = rssDetail != null ? rssDetail.InnerText : ""; NewsTableRow["Description"] = rssDetail != null ? GetFirstNWords(rssDetail.InnerText, WordsPerNewsItem) : ""; NewsTable.Rows.Add(NewsTableRow); catch return NewsTable; protected string GetFirstNWords(string input, int n) String[] words = input.Split(' '); StringBuilder sb = new StringBuilder(); int i = 0; while (i < words.Length - 1 && i < n) sb.Append(words[i] + " "); i++; sb.Append("..."); return sb.ToString(); Thanks for this code, however, it seems to display the title as the link in the URL.
Thanks for this code, however, it seems to display the title as the link in the URL.
That's right, the title is a hyperlink. If you need plain text, you can use anything else instead of asp:HyperLink. For example:
<asp:Label ID="Label1" runat="server" Text = '<%#Eval("title")%>'></asp:Label>
or
<h3><%#Eval("title")%></h3>
I created this widget through Thunder and added your code but I have this error...
The name 'rssRepeater' does not exist in the current context
Do you know how I can fix this?
Thanks!
I fixed the control issue with the code below but how do you pass a RSS URL into the control?
private Control FindControlRecursive(Control root, string id) if (root.ID == id) return root; foreach (Control c in root.Controls) Control t = FindControlRecursive(c, id); if (t != null) return t; return null; protected void Page_Load(object sender, EventArgs e) if (!String.IsNullOrEmpty(RssFeedUrl)) Repeater rssRepeater = FindControlRecursive(Page, "rssRepeater") as Repeater; rssRepeater.DataSource = GetTable(RssFeedUrl); rssRepeater.DataBind();