How to avoid that a string splits on every whitespace in command line
c#
Solution
You need to surround it with quotation marks:
"This is a test file.dotx"
MSDN:
Command line arguments are delimited by spaces. You can use double quotation marks (") to include spaces within an argument.
Problem
I'm writing a program in which the user can type in some informations about a customer and then open a MS Word model (*.dotx). After that he can directly archive it with another program. So I click on a button which I created for MS Word and then it should open the other program (the archive program) and pass the path to the *.dotx file to it. I got this code to pass the path and open the archive program: ``` Process p = new Process(); p.StartInfo.Arguments = "Word " + secondArgument; p.StartInfo.FileName = fileName; p.Start(); ``` The string `secondArgument` ist the path to the file and `fileName` is the path to the exe file of the archive program. To get the arguments in the archive program, I use this code in `Form_Load()`: ``` string[] args = Environment.GetCommandLineArgs(); ``` Then I use a MsgBox to look if it's correctly passed. But it isn't. The name of the .dotx file has whitespaces in it (e.g. "path\This is a test file.dotx"). So the output of `MessageBox.Show(args[0])` is "path\This". How can I avoid that it splits at every whitespace? Suggestions appreciated :)