【发布时间】:2015-11-12 18:56:15
【问题描述】:
我正在开发我的第一个 C# 应用程序。我正在尝试以全屏模式打开 PowerPoint 文件。该代码需要 cmd 参数。我将我的 powerpoint test.pptm 放在与我的应用程序的输出(调试和发布)相同的文件夹中。我写了以下代码:
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "powerpnt.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = "/s test.pptm";
try
{
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
}
}
catch
{
}
代码可以编译,但是当我尝试通过按钮运行此代码时,控制台显示:
Exception thrown: 'System.ComponentModel.Win32Exception' in System.dll
我尝试通过更改以下行来直接引用 pptm 文件:
startInfo.Arguments = "/s c:\path\to\full\file\test.pptm";
我收到一条错误消息,指出 Unrecognized escape sequence。有谁之前经历过这个吗?我已经坚持了一段时间。谢谢!
【问题讨论】:
-
你能帮我试试这个吗?
startInfo.Arguments = "/s ""c:\path\to\full\file\test.pptm"""; -
@PauloLima 谢谢,让我把完整的路径。但主要问题仍然存在,即
Exception thrown: 'System.ComponentModel.Win32Exception' in System.dll。该程序似乎具有所需的正确命令,但无法执行。 -
看看this post能不能帮到你
-
@PauloLima 该解决方案对我有用。另一种解决方案(本文中的答案之一)也起到了作用。谢谢!
标签: c# powerpoint