如何使用 Process.Start 打开 word 文件(带空格的路径)?

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

文件在目录中但空格导致此错误:

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

显示这条消息

和 这个

由于您的路径包含空格,并且程序参数通常由空格分隔,因此您的 outfile 被解释为 3 个不同的参数。您需要将路径括在引号中才能使其正常工作。

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

引号必须加倍,因为您使用了逐字字符串。

前提是Winword.exe是你默认的Word文档应用,你只需要在进程Filename属性中指定文档的路径如下

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

在 Visual Studio 2015 社区版

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