Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Process.Start(url) with anchor in the url

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

like image 557
Richard B Avatar asked Mar 08 '10 20:03

Richard B


2 Answers

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");
like image 168
Jason Kresowaty Avatar answered Nov 17 '22 11:11

Jason Kresowaty


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.

like image 23
Helge Klein Avatar answered Nov 17 '22 10:11

Helge Klein