Sandwich
Sandwich

Reputation: 356

Open PowerPoint presentation in slideshow mode - C#

I'm trying to open a PowerPoint presentation directly in slide show mode. I've tried using a Process (as shown below), but I get an error message from PowerPoint saying it can't find the file, error message "PowerPoint can't read C://Users/Route%20Plotter.pptx". The issue is caused by the white space in the file name as it works when this is removed.

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();

I've tried using the Office introp method (below), but can't get that to open directly in slideshow mode.

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)

Any ideas how to stop it changing the whitespace to a %20 (I'm already adding quotes round the path), or another way to open the file directly into slideshow mode, would be appreciated.

(I'm using VS2013 and PowerPoint 2013).

Upvotes: 2

Views: 6471

Answers (2)

Sandwich
Sandwich

Reputation: 356

Thanks to DavidG, the issue was the direction of the slashes. Forward slashes (/) are for URI and back slashes (\) are for file paths. Replacing the forward slashes with backslashes fixes the issue.

Upvotes: 0

Saba
Saba

Reputation: 71

Following code will be used to run the slide show mode for Power Point. Just you replace the file path is enough.

        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();

Upvotes: 1

Related Questions