views:

30

answers:

2

This is .NET 2.0 WinForms. I have some code like so

string str = Path.GetTempFileName();
Process p = new Process();
ProcessStartInfo psi = new ProcessStartInfo();
psi.Arguments = str
psi.FileName = <some executable >
p.StartInfo = psi;
p.Start();

Now on the "started" process I get the temp file name by saying args[0]. On Win XP this is causing an issue as the temp file is in C:\Documents and Settings\.... The space is causing an issue, thus args[0] is C:\Documents.

How can I fix this? Do I just have to place str in quotes? Or can I get the whitespace to be ignored somehow?

+1  A: 

Yes, use quotes.

crtracy
More than that, you should always use quotes in this scenario because you never know what paths you might run into. The temporary file location, like many other paths, can be customized to be anywhere.
Alex Paven
A: 

You can either wrap the path in double quotes or you can convert the path into its short (8.3) representation using the native GetShortPathName function.

Nathan Baulch