我正在尝试从 c# Windows 表单启动 Chrome 的外部实例。只要本地 html 文件的路径中没有空格,它就可以正常工作。如果 Chrome 在第一个空格处停止。
例如: "file:///C:/Users/user/Documents/Visual"
我试图通过像 Chrome 通常那样用“%20”替换字符串中的空格来解决这个问题。现在我得到这个乱码地址:
"file:///C:/Users/user/Documents/Visual%2520Studio%2520%2012/TEMP.html"
这是我的代码片段:
string chromeTempFilePath = tempFilePath.Replace(" ", "%20");
Process.Start(browserPaths[2], chromeTempFilePath);//launch Chrome
Process.Start
适用于 Firefox 和 IE 9,路径中有空格。任何帮助将不胜感激,因为我或多或少难倒了!
最佳答案
删除 string.Replace
方法并更改您的 Process.Start
看起来像这样:
Process.Start(browserPaths[2], string.Format("\"{0}\"", chromeTempFilePath));
您只需要将其全部用双引号括起来即可。这对我的 Chrome 有用,但我没有检查其他浏览器。
关于c# - 启动 Chrome 时尝试传递空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13533301/