launch default web browser so user can select a page, then get URL

Started by scott, June 21, 2021, 10:14:35 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

scott

I have a Visio add-in from which I want to give the user the opportunity to browse the web so they can select a target page. At that point, I want to capture the URL of the target page, and do some processing of the page's HTML.

The current version of the app accomplishes this by launching Internet Explorer and leveraging the connection between Windows and IE. This works because launching IE from within the app automatically transmits the URL back to the app.

However, IE is dead, so I need to accomplish the same thing using the default browser on the user's computer.

To say that a bit more specifically, I need to do the following from C#:

  • Launch the user's default web browser so the user can visit a website of their choice.
  • Retrieve the URL of the last page the user visits.
  • Retrieve the HTML of the selected page.

Suggestions?

BTW, I experimented with System.Windows.Forms.WebBrowser and can do much of what I need -- except that WebBrowser needs to be embedded in a Windows form and doesn't launch the default web browser. Here's an example that illustrates what I'm thinking:
void Main()
{
   UseWebBrowserObject();
}
private void UseWebBrowserObject()
{   
   WebBrowser web = new WebBrowser();
   web.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(web_DocumentCompleted);
   
   web.Navigate("http://www.xyz.com");
}

private void web_DocumentCompleted(Object sender, WebBrowserDocumentCompletedEventArgs e)
{
   MessageBox.Show(e.URL.ToString());

   WebBrowser wb = ((WebBrowser)sender);
   // use wb to retrieve and process html
 
}