views:

169

answers:

3

I want to open a file from a Class in C# using a Process, located in a directoy I asked the user.

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "EXCEL.EXE";
startInfo.Arguments = Here goes the directory I asked
Process.Start(startInfo);

The problem, is that when the location of the file indicated by the user has an space," ", excel thinks that I'm sending two sepparate locations. For example with C:\Users\dj\Desktop\da ba excel tries to open " C:\Users\dj\Desktop\da" as one file, and at the same time "ba" as another file. How can I send a location to excel which has an space, without having this error? with an addres like C:\Users\dj\Desktop\daba without an space it works perfectly.

+1  A: 

Try using a string literal

startInfo.Arguments = @"C:\Users\un\Desktop\file with space"
Sev
+1  A: 

Try quoting your path:

startInfo.Arguments = "\"" + "C:\Users\dj\Desktop\da ba.xls" + "\"";

Tim

Tim
A: 

Ok, thank you all, this way works

"\"" + @dialog.FileName + "\"";

=D