gaynorvader
gaynorvader

Reputation: 2657

Trying to pass spaces when launching Chrome

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!

Upvotes: 3

Views: 2435

Answers (1)

Chris Missal
Chris Missal

Reputation: 6123

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.

Upvotes: 4

Related Questions