Implement RSS news feed in .Net

There are many ready to use RSS wrappers on the net, the one from Web Service Share is easy to use and comes on top from Google search.
Download two DLL,

  • Wss.Common.dll
  • Wss.News.WebService.PcWorldNews.GetDataFeed.dll

from Class Library add them to the Bin folder. Add the following snippet to the aspx markup.

<asp:Literal ID="Literal1" runat="server" EnableViewState="False"></asp:Literal>

The code behind file.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
using Wss.Common;
using WebServices = Wss.News.WebServices;
using Rss = Wss.News.Rss20;
 
 
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int _rssNum = 10;
        Rss.Result rssResult = WebServices.PcWorldNews.GetDataFeed();        
        foreach (var _rss in GetRss.SelectRss(rssResult,   _rssNum))
        {
            Literal1.Text += String.Format("<a href="{1}">{0}</a><br /><hr />", 
                _rss.Title, _rss.Link);
        }        
    }
}
 
public struct aRss {
    public string Title { get; set; }
    public string Link { get; set; }    
    //public string Description { get; set; }    
}
static public class GetRss {    
 
    static public List<aRss> SelectRss(Rss.Result rssResult, int _rssNum)
    {        
        List<aRss> allRss = new List<aRss>();
        for (int i = 0; i < Math.Min(_rssNum, rssResult.Items.Count); i++)
        {
            allRss.Add(new aRss
            {
                Title = rssResult.Items[i].GetTitle(""),
                Link = rssResult.Items[i].GetLink(""),
                //Description = _item.GetDescription("")                
            }
            );
        }        
        return allRss;
    }
}

The class will return only the first 10 entries. The number is specified by the variable “_rssNum”.