Reputation: 448
I am working on my first C# application. I am trying to open a PowerPoint file in fullscreen mode. The code requires cmd arguments. I placed my powerpoint test.pptm
in the same folder as the output (debug and release) for my application. I have written the following code:
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
{
}
The code compiles, but when I try to run this code via a button, the console states:
Exception thrown: 'System.ComponentModel.Win32Exception' in System.dll
I've tried to directly reference the pptm file by changing the following line:
startInfo.Arguments = "/s c:\path\to\full\file\test.pptm";
I get an error stating Unrecognized escape sequence
. Has anyone experienced this before? I've been stuck on this for a little while. Thanks!
Upvotes: 0
Views: 168
Reputation: 5771
Prefix your file path with the @ sign
startInfo.Arguments = @"/s c:\path\to\full\file\test.pptm";
From MSDN
A verbatim string literal consists of an @ character followed by a double-quote character, zero or more characters, and a closing double-quote character. A simple example is @"hello". In a verbatim string literal, the characters between the delimiters are interpreted verbatim, the only exception being a quote-escape-sequence.
https://msdn.microsoft.com/en-us/library/aa691090(v=vs.71).aspx
A few pointers regarding your code to get it working
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.FileName = "powerpnt.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = @"/s ""fullpath with spaces in file names""";
Upvotes: 4