如何使用锚(#)在C#中使用默认浏览器中打开HTML文件 [英] How to open html file with anchor(#) in C# with default browser
问题描述
我想打开C#中的上下文帮助文件。
在我没有指定锚,它完美的作品。
的Process.Start(C:/Help/Help.htm)
但是,当我指定锚,它不会打开
的Process.Start(C:/Help/Help.htm#_Toc342057538)
在内部它改变'#'
到%23
和路径变得 C:\ Help.htm%23_Toc342057538
该浏览器无法识别。
浏览器已成功打开路径C:\ Help.htm#_Toc342057538
如何制止这种自动转换由的Process.Start 。同样的行为被发现,如果我给锚标签作为另一个参数,或者使用的乌里类。
修改
同样的行为被观察到,当我输入字符串的窗口中运行。下面的命令也转换#
到 23%
,该浏览器无法识别。
镀铬C:/Help.htm#_Toc342057538
在我的Windows 7系统,以下两个打开C:\帮助\ Help.htm在Internet Explorer和滚动到_Toc342057538主播:
的Process.Start(IEXPLORE,文件:// C:/Help/Help.htm#_Toc342057538);
的Process.Start(IEXPLORE,@C:\帮助\ Help.htm#_Toc342057538);
有关Firefox和Chrome,只有文件
的协议似乎工作:
的Process.Start(火狐,文件:// C:/Help/Help.htm#_Toc342057538);
的Process.Start(铬,文件:// C:/Help/Help.htm#_Toc342057538);
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
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");
这篇关于如何使用锚(#)在C#中使用默认浏览器中打开HTML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!