Click here to Skip to main content
15,887,967 members
Articles / Security

How to Open Web Page in Internal Browser of Visual Studio

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
14 Dec 2014CPOL2 min read 10.7K   1  
How to open a web page in internal browser of Visual Studio

This was originally posted on http://geekswithblogs.net/onlyutkarsh/archive/2013/12/06/how-to-open-web-page-in-internal-browser-of-visual.aspx.

Tarun and I have started working on a new Visual Studio extension which we plan to release in a couple of weeks after Christmas. One of the first things I do as soon as we start the work on a new tool/extension is to gather all the features we have planned and build as many sample extensions as I can (each extension doing part of the functionality which is demo-able). This helps me to get the sense of complexity and also minimal code needed for a functionality to work. Another benefit is, we get the advantages and limitations of the implementation. This helps us to look for other alternatives if the PoC doesn't fit our need or is too complex to build in the given time frame.

As part of this new extension, we need to open a web page on click of a hyperlink. But we do not like it to be opened in the external browser, rather we wanted it to be opened within Visual Studio itself. What I thought as a complex functionality, turned out to be too simple. This is pretty easy to implement with only 3 lines of code.

Visual Studio SDK has IVsWebBrowsingService interface, which has Navigate method. This will open the URL within Visual Studio itself.

C#
IVsWindowFrame ppFrame;
var service = Package.GetGlobalService(typeof (IVsWebBrowsingService)) as IVsWebBrowsingService;
service.Navigate("http://www.visualstudio.com/", 0, out ppFrame);

The second parameter in the Navigate method takes __VSWBNAVIGATEFLAGS enum. I am passing zero, which force creates browsing tab if doesn't exist already and uses if it exists. If you want to create a new tab every time the link is pressed, you can use __VSWBNAVIGATEFLAGS.VSNWB_ForceNew in 2nd parameter of Navigate method.

Click here to watch demo.

Also, I have put a sample project file for you to quickly run and see how it works. You can download it from here - https://github.com/onlyutkarsh/LaunchUrlDemo/.

License

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


Written By
Engineer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --