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

Posted on 2006-05-01
Last Modified: 2010-08-05

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,
Question by:tmitchell68
    LVL 85

    Assisted Solution

    by:Mike Tomlinson

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

    Accepted Solution

    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.
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    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.  =)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now