Visual Studio Tip of the Day Browser

Visual Studio Tip of the Day Browser

  • Comments 10

I'm sitting here with writer's block on an article I'm supposed to be writing so in order to coax the technical writing muse I decided to write an application I've been meaning to do for over a month. If you didn't know, on Sara's blog she has a category called Visual Studio Tip of the Day where she posts little VS gems. I wanted to be able to easily search by my own keywords through all the tips she's posted so far so I figured it would be a simple LINQ to XML query to do it. I was right.

First I added the RSS schema using the XML to Schema new item template and pointed it to her blog's RSS feed. This added the RSS schema information (.xsd files) to my project in order to enable XML IntelliSense. Next I created a class called Tip that simply contains the properties that I was interested in from the feed; Published, Link, Title and Text.

Public Class Tip

 

    Private m_link As String

    Public Property Link() As String

        Get

            Return m_link

        End Get

        Set(ByVal value As String)

            m_link = value

        End Set

    End Property

 

 

    Private m_title As String

    Public Property Title() As String

        Get

            Return m_title

        End Get

        Set(ByVal value As String)

            m_title = value

        End Set

    End Property

 

 

    Private m_date As Date

    Public Property Published() As Date

        Get

            Return m_date

        End Get

        Set(ByVal value As Date)

            m_date = value

        End Set

    End Property

 

 

    Private m_text As String

    Public Property Text() As String

        Get

            Return m_text

        End Get

        Set(ByVal value As String)

            m_text = value

        End Set

    End Property

 

End Class

Next I loaded up an XDocument from her feed and started to write my query. What I want to end up with is a collection of my Tip objects I defined above. To do this, in your Select clause you use the syntax "Select New ClassName With {", like this:

Dim Feed = XDocument.Load("http://blogs.msdn.com/saraford/rss.xml")

Dim searchTerm = "*" & Me.TextBox1.Text.ToLower & "*"

 

'This is the fun part. Select the tips we want from Sara's rss feed.

' This query creates a collection of our Tip class.

Dim tips = _

         From item In Feed...<item> _

          Let Published = CDate(item.<pubDate>.Value).ToLocalTime _

          Let Title = item.<title>.Value _

          Let Link = item.<link>.Value _

          Let Text = item.<description>.Value _

          Let Category = item.<category>.Value _

         Where Category IsNot Nothing AndAlso _

               Category.ToLower Like "*tip of the day*" AndAlso _

              (Title.ToLower Like searchTerm OrElse _

               Text.ToLower Like searchTerm) _

         Order By Published Descending _

         Select New Tip With _

          {.Published = Published, _

          .Title = Title, _

          .Link = Link, _

          .Text = Text}

I've got a textbox on the form that I'm using to type in keywords to search through the titles and the text of all the posts in the feed. I use .ToLower so that the keyword search is case insensitive. Now that we have a collection of our Tip objects we can easily bind this to a DataGridView and display the selected tip's text (which is the description in the RSS) inside a WebBrowser control for instance.

Notice here, I typed the keyword "editor" and it found posts with both editor in the title and the description text. I've put the application into Code Gallery for you to play with. It does a couple additional things (unrelated to the LINQ query) like stores the URI in My.Settings, loads the rss feed only once per day (otherwise it loads from a cache file), as well as loading on a background thread so not to block the UI. You can also click on the hyperlink below the grid to navigate the WebBrowser to the actual post so you can add/view the post comments online.

Enjoy!

Leave a Comment
  • Please add 8 and 7 and type the answer here:
  • Post
  • It would be useful to make this project more generalised by allowing the user to specify the URI to be searched.

  • Mike, that would take you 10 seconds to change the code to do that.  Seriously.

    Very cool example, Beth.  It really illustrates the new powerful features and now I have a thousand things running through my mind on how I could use them!

    You're doing a pretty good job of getting me excited for the release, keep it up.

    Thanks!

  • Oh, Mike, forgot to mention that the code looks for matches in the category node.  So, if you want to change the URI to something else, that new URI had better have a category node with "*tip of the day*" in it or your getting no matches.

    Did you even read the post?!

  • Hi Mike, you can easily add another textbox (I'd suggest with auto-complete) to capture the feed URI and then save that in My.Settings. With the category you can either allow the category to be entered in the UI as well or you can remove the category filter from the query and specify the tagged feed instead. i.e. For Sara's tip of the day feed you can directly access it here: http://blogs.msdn.com/saraford/rss_tag_Visual+Studio+2008+Tip+of+the+Day.xml

    Josh, I'm excited you're excited! :-)

  • A small comment about running your application with Vista.

    I kept getting access denied for c:tiprss.xml, so i just moved it to another temp folder and it was working perfectly.

    I like you application and will add it to my R&D collection;)

    ash

  • I made some modifications to my Visual Studio Tip of the Day browser application I created last week.

  • What about support of http://dotnettipoftheday.org ? :)

  • Welcome to the thirty-sixth issue of Community Convergence. This is the big day, with Visual Studio 2008

  • Welcome to the thirty-sixth issue of Community Convergence. This is the big day, with Visual Studio 2008

  • So what Turkey Day was last week?&#160; No reason why we can&#39;t have a second helping of tip of the

Page 1 of 1 (10 items)