Ahmed Emad Ahmed Emad - 2 months ago 17
C# Question

How do I use Process.Start to open a word file (Path with Spaces)?

The file is in the directory but the spaces cause this error:

string outfile = @"C:\Users\hp\Desktop\New folder (4)\outFile.doc";
Process.Start("WINWORD.EXE", outfile);


Shows me this message



and
this


Answer

Provided that Winword.exe is your default application for Word documents, all you need is to specify your document's path in the process Filename property as follows

        Process p = new Process();
        p.StartInfo.FileName = @"C:\Users\Someone\Documents\Path With Spaces\Word.docx";
        p.Start();

Tested in Visual Studio 2015 Community Edition