Monday, October 15, 2012

Filtering RSS Feed using LINQ & Binding ASP.NET ListView

In this article, I would like to demonstrate how we can parse RSS feeds & filtering from website and display on asp.net ListView.
ASP.Net Namespaces :C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.ServiceModel.Syndication;
using System.Xml.Linq;
using System.Linq.Expressions;
using System.Xml;
GetRSS Function: The GetRSS function is responsible to pull the RSS feed & filtering and display it on the web page.
Refer the code below C#
private void GetRSS()
{
string Subcategory = "Winne"; // searching keyword
string rssUri = "http://www.just-drinks.com/mhusa/rssdata.aspx?feed=wine";//Your RSS Url
var doc = System.Xml.Linq.XDocument.Load(rssUri);
var rssFeed = from el in doc.Elements("rss").Elements("channel").Elements("item")
              where el.Element("title").Value.ToLowerInvariant().Contains(Subcategory.ToLowerInvariant()                ||el.Element("description").Value.ToLowerInvariant().Contains(Subcategory.ToLowerInvariant())
             select new
             {
                 Title = el.Element("title").Value,
                  Link = el.Element("link").Value,
                  Description = el.Element("description").Value
              };

lvFeed1.DataSource = filterrssFeed;// Listview
lvFeed1.DataBind();}
Display the retrieved RSS Feeds To display the data I am using ASP.Net list view Control Refer below:





  • ” style=”color: Black;text-decoration: none; font-size: small”> <%#Eval(“Title”) %>
  • I hope you like this article. Enjoy!

    No comments:

    Post a Comment