1

I've got this path;

path = Cash Report\\30-03-2012 01-11-07 Cash Flow Report.Docx

When I use the below code to open the file it trys to open each word. SO it'll try open cash.doc, then Report.doc etc etc;

//Open the newly created file
        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.FileName = "WINWORD.EXE";
        startInfo.Arguments = path;
        Process.Start(startInfo);

Is there a way to ignore the spaces?!

r0bb077
  • 732
  • 2
  • 11
  • 33

3 Answers3

4

try

path="\"Cash Report\\30-03-2012 01-11-07 Cash Flow Report.Docx\""
Bob Vale
  • 18,094
  • 1
  • 42
  • 49
0
    String wordExe = "C:\\Program Files\\Microsoft Office\\Office14\\winword.exe";
    String filePath = "\"C:\\Users\\MainW8\\Documents\\название прецедента.docx\"";
    String command = String.format("%s /t %s",wordExe,filePath);
    System.out.println(command);

Output:
C:\Program Files\Microsoft Office\Office14\winword.exe /t "C:\Users\MainW8\Documents\название прецедента.docx"

Sergey Orlov
  • 349
  • 2
  • 5
0

this solution works:

Program that starts WINWORD.EXE [C#]

using System.Diagnostics;

class Program
{
static void Main()
{
// A.
// Open specified Word file.
OpenMicrosoftWord(@"C:\Users\Sam\Documents\Gears.docx");
}

/// <summary>
/// Open specified word document.
/// </summary>
static void OpenMicrosoftWord(string f)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "WINWORD.EXE";
startInfo.Arguments = f;
Process.Start(startInfo);
}

}

just tested, from http://www.dotnetperls.com/process-start

Greetings

Mario Fraiß
  • 1,095
  • 7
  • 15
  • why are you voting down? you have nothing said about the path of your files... C:\ i wrote was just an example.. – Mario Fraiß Mar 30 '12 at 00:20
  • 1
    I didn't vote it down, i just added the comment. Your answer won't work and will exhibit the same problems that the op is having. You need to have extra quotes round the path to get word to treat it as a single file rather than a list of files – Bob Vale Mar 30 '12 at 00:25
  • no it doesn't That just means the string won't escape things like \ – Bob Vale Mar 30 '12 at 00:26
  • The problem is when you call process start it will split based on spaces, you need the extra quotes in to get process start to treat it as a single argument. – Bob Vale Mar 30 '12 at 00:29