Process.Start(url) with anchor in the url
Asked Answered
S

2

5

I am trying to use Process.Start to launch a local html file in the default browser.

An example url is as follows:

"file:///C:/Documentation/HelpContent/default_CSH.htm#SectionA/Topic1.htm"

Problem is, the "#SectionA/Topic1.htm" bit gets stripped off for some reason, so that this information isn't passed to the browser. It does however work fine for a non-local url.

Does anyone know how I can get this to work or is it some sort of preventative security issue?

thanks

Slough answered 8/3, 2010 at 20:21 Comment(3)
The address works if you paste it in the browser address bar? Try to remove the / character from the anchor label...Eastlake
Yeah I agree. There are two filenames in that URL, which is kinda odd.Jenks
Unfortunately the / is required there - the url is like that because it is launching Topic1.htm in another frame (this is WebHelp output from MadCap Flare)Slough
D
4

Use Process.Start on iexplore.exe, so that you can specify the URL specifically as its argument:

System.Diagnostics.Process.Start("iexplore.exe", @"file:///c:/dir/file.html#anchor");
Diffuser answered 9/3, 2010 at 23:45 Comment(1)
Thanks - have used this method for the time being. Really I need to be able to open it in the default browser rather than restrict to IE.Slough
R
3

Launching a URL with an anchor in a browser does not work if you let the OS determine the default browser. The only way to make this work is to specify the browser's executable as binarycoder wrote for IE. It works the same way for Firefox.

The best solution is obviously to determine the path to the default browser from the registry and then specifically call that executable.

Radiolocation answered 30/3, 2011 at 16:19 Comment(1)
Here is a nice article showing you how to get the default browser path from the registryIdolatrous

© 2022 - 2024 — McMap. All rights reserved.