Visual Studio Tip of the Day Browser

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!