Visual Studio Macro for Live Search


Here is a Visual Studio macro that takes the highlighted text and starts a search of the msdn/msdn2 sites.  It often works better than the built-in help system.  I usually assign it to hot key Alt+F1.


 



‘————————————————————————–


‘You will need to add a reference to ‘System.Web’ for HttpUtility.UrlEncode


‘————————————————————————–


Public Sub SearchLiveForSelectedText()


    Dim s As String = ActiveWindowSelection().Trim()


    If s.Length > 0 Then


        ‘If there is a space, then put quotes around the phrase.


        Dim i As Integer


        i = s.IndexOf(” “)


        If i <> -1 Then


            s = “””” & s & “”””


        End If


 


        ‘Adding ‘header library’ to the search string helps focus


        ‘the search on non-.NET stuff


        Dim ext As String = LCase(Path.GetExtension(ActiveDocument().Name))


        If ext = “.cpp” Or ext = “.inl” Or ext = “.hpp” Or ext = “.cxx” Then


            s = s + ” header library “


        End If


 


        DTE.ItemOperations.Navigate(“http://www.live.com/?searchonly=true&q=” & _


            Web.HttpUtility.UrlEncode(s) & ” (site:msdn2.microsoft.com OR site:msdn.Microsoft.com)”)


    End If


End Sub

Comments (1)

  1. Julia Thomas says:

    I am replying to your blog because I don’t want to clean the kitchen.  This is your sister saying hello from the deep south.  I don’t understand any of the code, but it looks impressive!