Logo
HOWTO: Open the Web Browser and navigate to a page from a Visual Studio add-in or macro

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio .NET 2002
Date: May 2008   Microsoft Visual Studio .NET 2003
Updated: March 2013   Microsoft Visual Studio 2005
      Microsoft Visual Studio 2008
      Microsoft Visual Studio 2010
      Microsoft Visual Studio 2012
Introduction

This article explains how to open the Web Browser window of Visual Studio and navigate to a web site.

More Information

To open the Web Browser window of Visual Studio and navigate to a web site you have to use the following method of the Visual Studio automation model (EnvDTE):

 EnvDTE.DTE.ItemOperations.Navigate(url, options)

The method receives as parameters the URL and the navigation options (EnvDTE.vsNavigateOptions enumeration) and it returns the EnvDTE.Window of the Web browser.

The following code shows an add-in that navigates to the Microsoft web site when loaded:

Imports System
Imports Microsoft.VisualStudio.CommandBars
Imports Extensibility
Imports EnvDTE

Public Class Connect
   Implements IDTExtensibility2

   Private m_objDTE As DTE

   Public Sub OnConnection(ByVal application As Object, ByVal connectMode As ext_ConnectMode, _
      ByVal addInInst As Object, ByRef custom As Array) _
      Implements IDTExtensibility2.OnConnection

      m_objDTE = CType(application, EnvDTE.DTE)

      Select Case connectMode

         Case ext_ConnectMode.ext_cm_AfterStartup
            Initialize()

         Case ext_ConnectMode.ext_cm_Startup
            ' OnStartupComplete will be called
      End Select

   End Sub

   Public Sub OnStartupComplete(ByRef custom As Array) Implements IDTExtensibility2.OnStartupComplete
      Initialize()
   End Sub

   Public Sub OnDisconnection(ByVal disconnectMode As ext_DisconnectMode, ByRef custom As Array) _
      Implements IDTExtensibility2.OnDisconnection
   End Sub

   Public Sub OnAddInsUpdate(ByRef custom As Array) _
      Implements IDTExtensibility2.OnAddInsUpdate
   End Sub

   Public Sub OnBeginShutdown(ByRef custom As Array) _
      Implements IDTExtensibility2.OnBeginShutdown
   End Sub

   Private Sub Initialize()

      Dim objWindow As EnvDTE.Window

      objWindow = m_objDTE.ItemOperations.Navigate("http://www.microsoft.com", vsNavigateOptions.vsNavigateOptionsNewWindow)

   End Sub

End Class

Related articles


Go back to the 'Resources for Visual Studio .NET extensibility' section for more articles like this


Top