以幻灯片模式打开PowerPoint演示文稿-C#

以幻灯片模式打开PowerPoint演示文稿-C#,c#,powerpoint,C#,Powerpoint,我正在尝试以幻灯片放映模式直接打开PowerPoint演示文稿。我尝试使用一个进程(如下所示),但从PowerPoint收到一条错误消息,说它找不到文件,错误消息是“PowerPoint无法读取C://Users/Route%20Plotter.pptx”。该问题是由删除文件名时文件名中的空白引起的 string powerPointPath = @"C:\Program Files\Microsoft Office 15\root\office15\powerpnt.exe"; strin

我正在尝试以幻灯片放映模式直接打开PowerPoint演示文稿。我尝试使用一个进程(如下所示),但从PowerPoint收到一条错误消息,说它找不到文件,错误消息是“PowerPoint无法读取C://Users/Route%20Plotter.pptx”。该问题是由删除文件名时文件名中的空白引起的

string powerPointPath = @"C:\Program Files\Microsoft Office   15\root\office15\powerpnt.exe";
string powerPointFilePath = "\"" + "C://Users/Route Plotter.pptx" + "\"";

Process powerPoint = new Process();
powerPoint.StartInfo.FileName = powerPointPath;
powerPoint.StartInfo.Arguments = " /S " + powerPointFilePath;
powerPoint.Start();
我尝试过使用Office简介方法(如下),但无法在幻灯片模式下直接打开

Microsoft.Office.Interop.PowerPoint.Application pptApp = new Microsoft.Office.Interop.PowerPoint.Application();
pptApp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
pptApp.Activate();

Microsoft.Office.Interop.PowerPoint.Presentations ps = pptApp.Presentations;
Microsoft.Office.Interop.PowerPoint.Presentation p = ps.Open(powerPointFilePath, 
            Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue)
如果您有任何想法可以阻止它将空格改为%20(我已经在路径周围添加了引号),或者以其他方式将文件直接打开到幻灯片模式,我们将不胜感激


(我使用的是VS2013和PowerPoint 2013)。

多亏了DavidG,问题是斜杠的方向。正斜杠(
/
)用于URI,反斜杠(
\
)用于文件路径。用反斜杠代替正斜杠解决了这个问题。

多亏了DavidG,斜杠的方向才是问题所在。正斜杠(
/
)用于URI,反斜杠(
\
)用于文件路径。用反斜杠替换正斜杠解决了问题。

以下代码将用于运行Power Point的幻灯片放映模式。只要替换文件路径就足够了

        Application ppApp = new Application();
        ppApp.Visible = MsoTriState.msoTrue;

        Presentations ppPresens = ppApp.Presentations;
        Presentation objPres = ppPresens.Open("C:\\Users\\Users\\Documents\\Projects\\LS\\WindowsFormsApp1\\PPT.pptx", MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);
        Slides objSlides = objPres.Slides;

        SlideShowWindows objSSWs;
        SlideShowSettings objSSS;
        //Run the Slide show                                
        objSSS = objPres.SlideShowSettings;
        objSSS.Run();
        objSSWs = ppApp.SlideShowWindows;
        while (objSSWs.Count >= 1) System.Threading.Thread.Sleep(100);
        //Close the presentation without saving changes and quit PowerPoint                             
        objPres.Close();
        ppApp.Quit();

以下代码将用于运行Power Point的幻灯片放映模式。只要替换文件路径就足够了

        Application ppApp = new Application();
        ppApp.Visible = MsoTriState.msoTrue;

        Presentations ppPresens = ppApp.Presentations;
        Presentation objPres = ppPresens.Open("C:\\Users\\Users\\Documents\\Projects\\LS\\WindowsFormsApp1\\PPT.pptx", MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);
        Slides objSlides = objPres.Slides;

        SlideShowWindows objSSWs;
        SlideShowSettings objSSS;
        //Run the Slide show                                
        objSSS = objPres.SlideShowSettings;
        objSSS.Run();
        objSSWs = ppApp.SlideShowWindows;
        while (objSSWs.Count >= 1) System.Threading.Thread.Sleep(100);
        //Close the presentation without saving changes and quit PowerPoint                             
        objPres.Close();
        ppApp.Quit();

您是否尝试过使用
@“path”
作为文件路径?此外,您的斜杠是错误的,路径应该是
C:\Users\Route Plotter.pptx
谢谢David。我从另一个应用程序获取路径,甚至没有注意到斜线方向。您是否尝试过使用
@“path”
作为文件路径?而且斜线方向不对,路径应该是
C:\Users\Route Plotter.pptx
谢谢David。我从另一个应用程序获取路径,甚至没有注意到斜线方向。