我正在處理我的第一個C#應用程序。我正嘗試以全屏模式打開PowerPoint文件。該代碼需要cmd參數。我將我的powerpoint test.pptm
放在與我的應用程序的輸出(調試和發佈)相同的文件夾中。我寫了下面的代碼:嘗試使用C打開PowerPoint文件時拋出異常#
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謝謝,讓我放完整路徑。但主要問題仍然存在,即拋出異常:System.dll中的'System.ComponentModel.Win32Exception'。該程序似乎有適當的命令需要,但它不能執行它。 –
看看[這篇文章](http://stackoverflow.com/questions/27596215/c-sharp-code-wont-launch-programs-win32exception-was-unhandled)可以幫助你 –