Specifying System.Diagnostics.Process.Start parameters with spaces in a parameter string

Hello,

I have a C# application that calls a process from the C# code.

One of the parameters is a filepath.  This works fine - as long as there are no spaces in the filepath.  If there are spaces in the filepath name, the app breaks.

For example, this works:

System.Diagnostics.Process.Start("c:\\Programs\\WinRar\\WinRar", "e c:\\Temp\\*.rar *.rcp");


This, however, does not work (notice that the only difference is that there is a space in the filepath string in the second argument):

System.Diagnostics.Process.Start("c:\\Programs\\WinRar\\WinRar", "e c:\\Temp Files\\*.rar *.rcp");

Thanks in advance,
Tim
tmitchell68Asked:
Who is Participating?
 
patspamCommented:
Try: System.Diagnostics.Process.Start("c:\\Programs\\WinRar\\WinRar", "e \"c:\\Temp Files\\*.rar\" *.rcp");

Eg, put in backslash-escaped quotes around the path with spaces, so that they don't get treated as 2 separate arguments.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Try...

    System.Diagnostics.Process.Start(@"c:\Programs\WinRar\WinRar", @"e ""c:\Temp Files\*.rar"" *.rcp");
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
That's exactly what I have done patspam...except I used the @ symbol in front of the string with double-double quotes...same end difference.  =)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.