[英]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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.