views:

54

answers:

1

I'm writing an application that uses the PowerPoint interop library for Office 2010. It's supposed to open PowerPoint, load a presentation, and wait for the user to save the presentation after making changes. I want the application to upload the presentation to a server once updated.

The problem I'm having is that the PresentationSave or PresentationBeforeSave events are not being triggered when the presentation is saved.

Here's the code I've used:

private void startPPT()
{
        app = new ApplicationClass();

        app.WindowState = PpWindowState.ppWindowMaximized;
        app.Visible = MsoTriState.msoTrue;

        app.PresentationBeforeSave += new EApplication_PresentationBeforeSaveEventHandler(app_PresentationBeforeSave);
        app.PresentationSave += new EApplication_PresentationSaveEventHandler(app_PresentationSave);

        Presentation ppt;

        //check if it's pptx or ppt and open accordingly
        FileInfo fi = new FileInfo(filename);
        if (fi.Extension == ".pptx")
        {
            //version 2007
            ppt = app.Presentations.Open2007(filename, MsoTriState.msoFalse, MsoTriState.msoFalse);
        }
        else
        {
            //version 2003 or older
            ppt = app.Presentations.Open(filename, MsoTriState.msoFalse, MsoTriState.msoFalse);
        }
}

    void app_PresentationSave(Presentation Pres)
    {
        MessageBox.Show("Saved");
    }

Any ideas why it isn't working?

A: 

Ok, it turns out I had to use a delegate in the event handler. Here's the code that worked, in case anyone needs it for reference:

    private void startPPT()
    {
    // as above
    }

    private delegate void CallBackPPTSaved(Presentation p);

    void app_PresentationSave(Presentation Pres)
    {
        this.Dispatcher.BeginInvoke(new CallBackPPT(PPTEventHandler), System.Windows.Threading.DispatcherPriority.Normal, Pres);
    }

    private void PPTEventHandler(Presentation p)
    {
        MessageBox.Show("Saved");
    }
aethersb