Home | Blog | Screencasts | Projects
# Friday, August 15, 2008

Something a little less SharePoint. If you wanted to consume an RSS feed (such as my homepage) and your using .NET framework 3.5+, then you could use the following code:

 

XDocument rssFeed = XDocument.Load(@"http://httpcode.com/blogs/SyndicationService.asmx/GetRss");

var posts = from item in rssFeed.Descendants("item")
    select new
            {
                Title = item.Element("title").Value,
                Published = DateTime.Parse(item.Element("pubDate").Value),
                Url = item.Element("link").Value,

            };
//BlogPosts is a ListView
BlogPosts.DataSource = posts;
BlogPosts.DataBind();

How about taking my last 5 twitter posts, but lets remove my name:

 

XDocument twitterFeed = XDocument.Load(@"http://twitter.com/statuses/user_timeline/14554389.rss");

var titterPosts = from item in twitterFeed.Descendants("item")
            select new
            {
                Title = item.Element("title").Value.Replace("DanielPollard:","")                       

            };
//TwitterPosts is a ListView - Notice the Take(5) below
TwitterPosts.DataSource = titterPosts.Take(5);
TwitterPosts.DataBind();

 

There's a lot to love about Linq.

Friday, August 15, 2008 9:42:50 PM (E. Australia Standard Time, UTC+10:00)  #    Comments [0] - Trackback
code | Work
Tracked by:
"http://www.mynetfaves.com/tags/blogposts" (http://www.mynetfaves.com/tags/blogp... [Pingback]
Statistics
Total Posts: 134
This Year: 0
This Month: 0
This Week: 0
Comments: 20