Вопрос

I'm trying to launch an external instance of Chrome from a c# Windows form. It works fine as long as there are no spaces in the path of the local html file. If there are though Chrome stops at the first space. e.g. : "file:///C:/Users/user/Documents/Visual" I tried to fix this by replacing spaces in the string with "%20" like Chrome usually does. Now I get this garbled address: "file:///C:/Users/user/Documents/Visual%2520Studio%2520%2012/TEMP.html"

Here's a snippet of my code:

string chromeTempFilePath = tempFilePath.Replace(" ", "%20");

Process.Start(browserPaths[2], chromeTempFilePath);//launch Chrome  

Process.Start works fine for both Firefox and IE 9 with the spaces in the path. Any help would be much appreciated as I'm more or less stumped!

Это было полезно?

Решение

Remove the string.Replace method and change your Process.Start to look like this:

Process.Start(browserPaths[2], string.Format("\"{0}\"", chromeTempFilePath));

You just need to wrap it all in double quotes. This worked for me with Chrome, but I didn't check other browsers.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top