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


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,
Who is Participating?
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.
Mike TomlinsonMiddle School Assistant TeacherCommented:

    System.Diagnostics.Process.Start(@"c:\Programs\WinRar\WinRar", @"e ""c:\Temp Files\*.rar"" *.rcp");
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.  =)
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.