SyndicationFeed and Beating FeedProxy

by KodefuGuru 8. September 2009 16:05

Reading in a series of blog posts is made easy utilizing classes that came in the .NET Framework 3.5. As long as the feed is in the Atom 1.0 or RSS 2.0 formats, you easily build your own aggregator service.

SyndicationFeed feed = null;
using (XmlReader reader = XmlReader.Create(feedUrl))
{
    feed = SyndicationFeed.Load(reader);
}
foreach (SyndicationItem item in feed.Items)
{
}

Off of the item, you will probably want to grab the Title.Text and the Summary.Text. Be sure to HtmlDecode them! Another important thing is the Categories collection, which I’m using as tags. Here’s the line of code from my project: Tags = item.Categories.Select(c => c.Name).Aggregate((a, b) => a + "," + b).

Lastly, an aggregator would be pointless unless you were grabbing the url (get it from Links[0].Uri.ToString()). However, many feeds are using Feedburner. If you pull from feedburner, the url will be a feedproxy.google.com url instead of one that goes directly to the blog article. The trick to get around this turned out to be quite simple. Make a WebRequest to the feedproxy url then read the WebResponse’s url.

private static string GetTrueUrl(string url)
{
    if (url.StartsWith("http://feedproxy.google.com"))
    {
        var request = WebRequest.Create(url);
        using (var response = request.GetResponse())
        {
            url = response.ResponseUri.ToString();
            response.Close();
        }
    }
    return url;
}

That’s all there is to reading in standard feeds. I’ll leave it up to you to decide on a specific implementation.

Tags: , , , , ,

Kodefu

Comments

9/8/2009 4:06:44 PM #

trackback

Trackback from DotNetKicks.com

SyndicationFeed and Beating FeedProxy

DotNetKicks.com

9/8/2009 4:09:42 PM #

trackback

Trackback from WebDevVote.com

SyndicationFeed and Beating FeedProxy

WebDevVote.com

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.6.0.0
Theme by Mads Kristensen

Whois KodefuGuru

Chris Eargle

Chris Eargle
.NET Community Champion

LinkedIn Twitter Technorati Facebook

MVP - Visual C#

 

INETA Community Champions
Friend of RedGate
Telerik .NET Ninja
Community blogs & blog posts

I am a #52er


World Map

RecentComments

Comment RSS

Tag cloud

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010