C# Blog Reader - 2 - Get data into an app

Sign in to queue

Description

In this video we'll build a set of classes to represent a blog post, a blog, and a collection of blogs that download RSS or Atom feeds from the Web using the SyndicationClient class.

Changes in the video as of 3/25/2013

  • Change URLs to use blogs.windows instead of windowsteamblogs. For feed1, change it to use the new SkyDrive blog in place of the deleted Developers blog.

 

        public async Task GetFeedsAsync()

        {

            Task<FeedData> feed1 =

                GetFeedAsync("http://blogs.windows.com/skydrive/b/skydrive/atom.aspx");

            Task<FeedData> feed2 =

                GetFeedAsync("http://blogs.windows.com/windows/b/windowsexperience/atom.aspx");

            Task<FeedData> feed3 =

                GetFeedAsync("http://blogs.windows.com/windows/b/extremewindows/atom.aspx");

            Task<FeedData> feed4 =

                GetFeedAsync("http://blogs.windows.com/windows/b/business/atom.aspx");

            Task<FeedData> feed5 =

                GetFeedAsync("http://blogs.windows.com/windows/b/bloggingwindows/atom.aspx");

            Task<FeedData> feed6 =

                GetFeedAsync("http://blogs.windows.com/windows/b/windowssecurity/atom.aspx");

            Task<FeedData> feed7 =

                GetFeedAsync("http://blogs.windows.com/windows/b/springboard/atom.aspx");

            Task<FeedData> feed8 =

                GetFeedAsync("http://blogs.windows.com/windows/b/windowshomeserver/atom.aspx");

            // There is no Atom feed for this blog, so use the RSS feed.

            Task<FeedData> feed9 =

                GetFeedAsync("http://blogs.windows.com/windows_live/b/windowslive/rss.aspx");

            Task<FeedData> feed10 =

                GetFeedAsync("http://blogs.windows.com/windows_live/b/developer/atom.aspx");

            Task<FeedData> feed11 =

                GetFeedAsync("http://blogs.windows.com/ie/b/ie/atom.aspx");

            Task<FeedData> feed12 =

                GetFeedAsync("http://blogs.windows.com/windows_phone/b/wpdev/atom.aspx");

            Task<FeedData> feed13 =

                GetFeedAsync("http://blogs.windows.com/windows_phone/b/wmdev/atom.aspx");

            Task<FeedData> feed14 =

                GetFeedAsync("http://blogs.windows.com/windows_phone/b/windowsphone/atom.aspx");

 

 

  • In GetFeedAsync, don't add 'http://windowsteamblog.com' to the item id when processing an Atom feed. They've updated the id format, so we can just use the id now.

 

                        if (feed.SourceFormat == SyndicationFormat.Atom10)

                        {

                            if (item.Content != null && item.Content.Text != null)

                            {

                                feedItem.Content = item.Content.Text;

                            }

                            if (item.Id != null)

                            {

                                feedItem.Link = new Uri("http://windowsteamblog.com" + item.Id);    // just use feedItem.Link = new Uri(item.Id);

 

 

  • Check for null values in GetFeed and GetItem.

 

            var matches = _feedDataSource.Feeds.Where((feed) => feed != null && feed.Title.Equals(title));

 

 

            var matches = _feedDataSource.Feeds

                .Where(group => group != null)

                .SelectMany(group => group.Items).Where((item) => item.Title.Equals(uniqueId));

              

 

Embed

Download

Download this episode

The Discussion

  • User profile image
    martinmine

    Great video!
    I don't really see why you do the null checks (would have used string.IsNullOrEmpty anyways), but if they are null, the feed fields you wanted to set is in most case null Smiley

    Gonna start working on my Windows 8 app now, thanks for the kickstart! Big Smile

  • User profile image
    Elroymam

    I had a problem getting these feeds (mentioned around the 20:00 mark) to load properly in the app as described later in this demo series.  I was able to make it work by changing all atom.aspx URLs to rss.aspx.  Other than that, great series.  I look forward to using what I learned here in the very near future.

  • User profile image
    MSPNitesh

    Great video , but having one problem. when i right click on Rss Post,  it is not showing "save target as". it showing only "save link as". if i downloaded as and save it. is it correct.? then it is not working like a .xaml file.

    so please tell me from where i can get .xaml file of rss post. 

  • User profile image
    TonyBoySP

    The "high quality WMV" link is wrong... the file for the link is "Part20ImplementingTheSearchContract_Source.wmv"...

  • User profile image
    TonyBoySP

    The "high quality WMV" link is wrong... the file for the link is "Part20ImplementingTheSearchContract_Source.wmv"...

  • User profile image
    MSPNitesh

    can anyone help me am getting rss.aspx not rss.xaml file. please give me solution from where i can get.  

    when i  right click on rss post it shows save link as not save target as. when i downloaded this file.it's rss.aspx not rss.xaml file.

    Please give solution.

  • User profile image
    Dan

    , MSPNitesh wrote

    can anyone help me am getting rss.aspx not rss.xaml file. please give me solution from where i can get.  

    when i  right click on rss post it shows save link as not save target as. when i downloaded this file.it's rss.aspx not rss.xaml file.

    Please give solution.

    What browser are you using? Saving the file as RSS.aspx is fine, you'll notice that when you open it up, is it an XML file

  • User profile image
    Dan

    , TonyBoySP wrote

    The "high quality WMV" link is wrong... the file for the link is "Part20ImplementingTheSearchContract_Source.wmv"...

    Sorry about that, the video is correct if you download it, it's just that the label is wrong. I'll see what I can do to fix that Smiley

  • User profile image
    annaqeeb

    @Elroymam: I had the same problem too. As listed in http://blogs.windows.com/b/ , all feeds are now RSS only. Also the website changed its name

     

  • User profile image
    Houssem

    thank you for the great content .... i just fall in love of win 8 ... but i have the question .... when we give our app an XML file ... how it be regenerate or how the app can know that their's an update for these info or in other way how we can get " fresh info" each time while we put a single XML file ... ??

  • User profile image
    ads

    how can I make a sync feeddata from a playlist from youtube I've done it by retrieving the all videos from the total channel

    thank i'm really thankful

  • User profile image
    Dirtbagg

    Awesome video Dan, it is just what I've been looking for. \m/

  • User profile image
    PradeepReddy

    What did you copy and pasted in public async Task GetFeedsAsync(){ } method?

    I want to display youtube videos from a channel like that.
    How can I do that?

  • User profile image
    PradeepReddy

    What did you copy and pasted in public async Task GetFeedsAsync(){ } method?

    I want to display youtube videos from a channel like that.
    How can I do that?

  • User profile image
    annaqeeb

    @Dan: Thanks Dan for updating the video with the new links.  I really had some problems in running code, that I commented on this episode and the next episode proposing changing the links. I even wrote a feedback on the MSDN article. Now I think the code should run out of the box, and problems should be resolved! and it even has atom feeds, so the author name would be visible in the app when viewed in later episodes!

  • User profile image
    Shakti

    m getting error during feedData in this code
    ( private ObservableCollection<FeedData> _Feeds = new ObservableCollection<FeedData>();
    public ObservableCollection<FeedData> Feeds
    {
    get
    {
    return this._Feeds;
    }
    }
    )



    i find error in Feeds keyword please help me ...

  • User profile image
    Lucknow

    m have an other problem with   (  

     public static FeedData GetFeed(string title)        {            // Simple linear search is acceptable for small data sets            var _feedDataSource = App.Current.Resources["feedDataSource"] as FeedDataSource;            var matches = _feedDataSource.Feeds.Where((feed) => feed.Title.Equals(title));            if (matches.Count() == 1) return matches.First();            return null;        }

         )

     

    in 

    GetFeed keyword
  • User profile image
    harritvanbe​ek

    hi, i have i question,
    I can use for any feet a background image and display it in my itemPage, and when there is no picture to present.

    you than <SolidColorBrush x:Key="BlockBackgroundBrush" Color="#FF557EB9"/> color looks

Add Your 2 Cents