问题
I am trying to open a contextual help file in c#.
When i specify no anchor, it works perfectly.
Process.Start("C:/Help/Help.htm")
But when i specify anchor, it does not open
Process.Start("C:/Help/Help.htm#_Toc342057538")
Internally it changes '#'
to '%23'
and the path becomes "c:\Help.htm%23_Toc342057538"
which browser is unable to recognize.
Browser is successfully opening the path "c:\Help.htm#_Toc342057538"
How to stop this automatic conversion by Process.Start. The same behavior is observed, if i give the anchor label as another argument, or use Uri class.
EDIT
Same behavior is observed, when i enter the string in Window Run. Following command also convert #
to %23
, which browser cannot recognize.
chrome c:/Help.htm#_Toc342057538
回答1:
On my Windows 7 system, both of the following open C:\Help\Help.htm in Internet Explorer and scroll to the _Toc342057538 anchor:
Process.Start("iexplore", "file://C:/Help/Help.htm#_Toc342057538");
Process.Start("iexplore", @"C:\Help\Help.htm#_Toc342057538");
For Firefox and Chrome, only the file
protocol seems to work:
Process.Start("firefox", "file://C:/Help/Help.htm#_Toc342057538");
Process.Start("chrome", "file://C:/Help/Help.htm#_Toc342057538");
回答2:
Try this out. I just did it myself and working in internet explorer
string s = "file:///D:/tmp/test.html%23test";
s = uri.UnescapeDataString(s);
Process.Start(s);
Please let me know if it is working or not for you.
来源:https://stackoverflow.com/questions/13852867/how-to-open-html-file-with-anchor-in-c-sharp-with-default-browser