Freigeben über


Using SyndicationFeed to display photos from spaces.live.com

The SyndicationFeed class from System.ServiceModel.Syndicatation makes it easy to work with feeds and extensions. The code below uses an RSS feed from space.live.com to show photo albums on a page. Of course there are many ways to consume RSS with and w/o code, but the WCF enhancements with .NET 3.5 are a nice new trick. You can see the result at https://www.steveres.com/SpacesPics.aspx

r = XmlReader.Create("https://yournamegoeshere.spaces.live.com/photos/feed.rss");
albums = SyndicationFeed.Load(r);
r.Close();
foreach (SyndicationItem album in albums.Items)
{

// album.links[0].URI points to this album page on spaces.live.com
// album.Summary (not shown) is an HTML block with thumbnails of the album pics
cell.Text= string.Format("<a href='{0}'>{1}</a>", album.Links[0].Uri, album.Title.Text);
albumRSS = GetAlbumRSS(album);
r = XmlReader.Create(albumRSS);
photos = SyndicationFeed.Load(r);
r.Close();
foreach (SyndicationItem photo in photos.Items)
{
// photo.Summary is an HTML block with a thumbnail of the pic
      cell.Text = string.Format("{0}", photo.Summary.Text);
}

}
//
// helper to extract the feed to one album from the albums feed
//
private string GetAlbumRSS(SyndicationItem album)
{

string url = "";
foreach (SyndicationElementExtension ext in album.ElementExtensions)
       if (ext.OuterName == "itemRSS") url = ext.GetObject<string>();
return (url);

}

Comments

  • Anonymous
    January 20, 2008
    PingBack from http://msdnrss.thecoderblogs.com/2008/01/20/using-syndicationfeed-to-display-photos-from-spaceslivecom-2/

  • Anonymous
    March 11, 2008
    Hi Steve, I want to validate RSS feed url given by the user programmatically. Ofcourse, there are lot of web sites they do validate rss feeds...like http://validator.w3.org/feed/check.cgi?url="RSS Feed uRL"...it will validate and tell you the results. But i want to do programmatically using .NET ...so is there any API is available....it would be great if you help in this regard. Thanks & Regards, Kathir

  • Anonymous
    May 16, 2013
    Exception while reading r = XmlReader.Create("yournamegoeshere.spaces.live.com/.../feed.rss"); How can i give Proxy (407) Proxy Authentication Required

  • Anonymous
    June 06, 2013
    very helpful code. it helped me a lot.

  • Anonymous
    May 03, 2014
    Ashokraj we use webclient to solve this issue. using (WebClient client = new WebClient())            {                //set your proxy to client here                string data = client.DownloadString(url);                using (XmlReader reader = XmlReader.Create(new StringReader(data)))                {                    SyndicationFeed feed = SyndicationFeed.Load(reader);                    foreach (SyndicationItem item in feed.Items)                    {                        String subject = item.Title.Text;                        Console.WriteLine("{0}" , subject);                    }                }            }