Open a Web Document at a Specific Location

106 14
An About Visual Basic reader asked for help with this problem where the VB.NET statement ... Process.Start("file:///C:/mainpage.htm#detailpage.htm") ... would only open the mainpage.htm. They wanted to open the detail page instead and nothing they tried would do it. My friend noted that when URI ...

C:/mainpage.htm#detailpage.htm
... by itself was entered into the address field of the browser, everything worked as it should.

(The characters following the "#" in the URI are called a "fragment", also known as a "ref" or a "reference" in the web world.)

Microsoft would probably answer this problem with their dry, catchall response: "The behavior is by design." Out here in the real world where we're trying to use their products, we translate that into, "It's not a bug! It's a feature!"

The Process.Start method is documented here at About Visual Basic in a different article. You can read all about Process.Start by clicking here.

Unfortunately, I don't know of a way to use Process.Start to open the fragment URI because Process.Start will only pass a "file" in this context. And a fragment is technically not part of a file name. Process.Start actually "cleans up" the file name by deleting any extraneous information before passing it to Windows. That's why it's a "feature"!

You can do what the reader wants ... sort of. The WebBrowser component will accept a URI (not a file) so you can add that component to a VB.NET application and code it this way:

WebBrowser1.Navigate("file:///C:/mainpage.htm#detailpage.htm")
Then it works like a shot. But the web page is contained within the WebBrowser component pane. It doesn't run as an independent process in Windows this way.
Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.