Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.50/5 (4 votes)
See more:
Hi,

I have written following code to open .net application

C#
String path;
 path=@"D:\test App\dec\dec.sln";
 Process.Start("devenv.exe", path);


It has problem because 'test App' folder contain space.

Anybody knows any work around for this..

Thanks,
Nagraj
Posted
Updated 16-Jan-19 13:25pm
v2

Hi,
try this solution that works for me:
C#
string path = "\"D:\\test App\\dec.sln\"";
Process.Start("devenv.exe", path);
 
Share this answer
 
Comments
Espen Harlinn 16-Feb-11 15:01pm    
Nice and simple, my 5
I'm sorry for incorrect answer I posted in first place.

The problem is indeed blank spaces and only because of the second parameter.
First parameter is full path name of the file in one string, second parameter: command line.

Then blank spaces are normally not needed, but the problem is in the application run in the process to be launched: command is parsed into command line parameters delimited by blank spaces. If some parameter should come with blank spaces inside, it should be surrounded by quotation marks, otherwise it is broken: parsed as two or more parameters.

In this example "D:\test App\dec\dec.sln" was parsed as two parameters:
"D:\test" and "App\dec\dec.sln". Adding quotation make should fix it.

The correct fix is shown in the Answer by J2015.

—SA
 
Share this answer
 
v6
Comments
JF2015 16-Feb-11 2:42am    
I disagree. This error is related to blank spaces. The OP correctly uses Process.Start("devenv.exe", path) which starts visual studio with the solution specified under "path". His code works perfectly for me when using a path without spaces and my solution works even if there are spaces in the path.
Sergey Alexandrovich Kryukov 16-Feb-11 3:31am    
Nishant, you are right and you vote of "1" was correct, I realized my mistake later.
I apologize. I put explanation in the update of my Answer.
--SA
JF2015 16-Feb-11 3:34am    
I tested it with VS2008 and that is the only solution that worked for me.
Sergey Alexandrovich Kryukov 16-Feb-11 10:48am    
I was wrong. I fixed my answer: put detailed explanation.
Sorry.
--SA
Olivier Levrey 16-Feb-11 4:15am    
This must be the right answer. Quotes are not needed for parameters. I made a quick test and it worked.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900