1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / RSS Feed Reader For Sitefinity4.4 Available?

RSS Feed Reader For Sitefinity4.4 Available?

7 posts, 0 answered
  1. Satya
    Satya avatar
    4 posts
    Registered:
    18 Jan 2012
    10 Feb 2012
    Link to this post
    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..
  2. Serge G
    Serge G avatar
    9 posts
    Registered:
    10 Jun 2011
    12 Feb 2012
    Link to this post
    Hi Satya,

    Few weeks ago our company developed custom RSS Reader. It is simple widget that accepts Url and limits for displaying number of news and words per news item. Maybe it would be useful for you too.

    RSS.ascx 
    <%@ 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>


    RSS.ascx.cs 
    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();
        }
    }

  3. Chris Carrier
    Chris Carrier avatar
    4 posts
    Registered:
    11 Jan 2010
    23 Mar 2012
    Link to this post
    Thanks for this code, however, it seems to display the title as the link in the URL.
  4. Chris Carrier
    Chris Carrier avatar
    4 posts
    Registered:
    11 Jan 2010
    23 Mar 2012
    Link to this post
    Thanks for this code, however, it seems to display the title as the link in the URL.
  5. Serge G
    Serge G avatar
    9 posts
    Registered:
    10 Jun 2011
    24 Mar 2012
    Link to this post
    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>
  6. Highrad
    Highrad avatar
    15 posts
    Registered:
    22 Aug 2007
    23 May 2012
    Link to this post
    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!
  7. Highrad
    Highrad avatar
    15 posts
    Registered:
    22 Aug 2007
    24 May 2012
    Link to this post
    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();
        }
    }
7 posts, 0 answered