Click here to Skip to main content
Click here to Skip to main content

Invoke Google from within VS 2008

, 6 Dec 2009
Rate this:
Please Sign up or sign in to vote.
Invoking Google from within VS 2008

As programmers we need to search for many tasks that we want to accomplish. And the F1 key in Visual Studio does not help because it always launches the local MSDN search, even if MSDN is not installed on the local computer.

Brian Schmitt has provided the code to write a macro to search variouse sites. Here I am describing steps to how you can configure your Visual studio 2008 to invoke google search from within the IDE based on his post.

  • In the VS 2008 IDE, click Alt + F8 to launch the Macro explorer.  It should show you a tree like below at the right hand side of the IDE.  

 

  • Right Click on theMyMacros project and create a new module named Search. (Alternately, you can goto Tools menu-> Macros -> New Macro command). This will launch the macro editor.
  • Copy and paste the below code in the macro editor. (Code taken from Brian Schmitt's article on Better Visual Studio F1)
Imports EnvDTE
Imports System.Web

Public Module Search

#Region "Search Internet Sites"
  Public Const GOOGLE_FORMAT As String = "www.google.com/search?q={0}"
  Public Const STACKOVERFLOW_FORMAT As String = _
     "http://www.stackoverflow.com/search?q={0}"
  Public Const SEARCHDOTNET_FORMAT As String = _
     "http://searchdotnet.com/results.aspx?" & _
     "cx=002213837942349435108:jki1okx03jq&q={0}" & _
     "&sa=Search&cof=FORID:9#1144"
  Public Const MSDN_FORMAT As String = _
     "http://social.msdn.microsoft.com/Search/en-US/?query={0}&ac=8"
   
  Public Sub SearchStackOverflowForSelectedText()
      SearchWebPage(STACKOVERFLOW_FORMAT)
  End Sub
  Public Sub SearchGoogleForSelectedText()
      SearchWebPage(GOOGLE_FORMAT)
  End Sub
  Public Sub SearchSearchDotNetForSelectedText()
      SearchWebPage(SEARCHDOTNET_FORMAT)
  End Sub
      Public Sub SearchMSDNForSelectedText()
      SearchWebPage(MSDN_FORMAT)
  End Sub
  Private Sub SearchWebPage(ByVal SearchURLFormat As String)
      Dim sel As EnvDTE.TextSelection = DTE.ActiveWindow.Selection
      Dim srchTxt As String = sel.Text.Trim
      If srchTxt.Length > 0 Then
          DTE.ItemOperations.Navigate(String.Format(SearchURLFormat, _
                                      HttpUtility.UrlEncode(srchTxt)))
      End If
  End Sub
#End Region

End Module
  • Now the macro is ready (there are four macros created one each for google, stackoverflow, searchdotnet and MSDN). Now we will assign short cut for all the four macros.
  • Go to Tools -> Options -> keyboard. In the “Show command containing” type macro. Or simply scroll through the list box to find the macro we just created.  

 

  • In the “Press shortcut key” type in the short cut you want (for e.g. Alt + F1, Alt + Shift + F1). Note that if you press just F1, it will replace the existing binding for the F1 key to the MSDN help.
  • In the similar way type in the short cut for other macros.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Ashish Sheth
Software Developer (Senior) McAfee
India India
a 24/7 Programmer. Apart from programming, I do eat, sleep, breath for living. My areas of interests are C#, .Net Framework and Software development in general.
When I am not programming and not doing anything else(?), I play chess.

Comments and Discussions

 
GeneralVery Helpful Pinmembervikas amin12-Mar-10 6:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140709.1 | Last Updated 7 Dec 2009
Article Copyright 2009 by Ashish Sheth
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid