Add-in Express 2007 - Powerpoint Save File Dialog

Add-in Express™ Support Service
That's what is more important than anything else

Add-in Express 2007 - Powerpoint Save File Dialog
Need to invoke the SaveAs Dialog 
Andrew Bewley




Posts: 7
Joined: 2008-06-19
Hi,

When calling ActivePresentation.Save() on the Powerpoint object it saves the file to whatever the current folder may be with a default name.
I believe this is the default behaviour of the Powerpoint object model...

What I need to do is show the 'Save As' dialogue so the user can select the location and filename. How do I do this???

If i create an object of type PowerPoint.FileDialog the expected Show() method is missing. There is however a Launch(object pUnk) method, but I can't figure out what to do with it.

I'm toying with the idea of creating a .Net SaveFileDialog (passing the Powerpoint window handle) and then calling the SaveAs method, however this means i'd have to duplicate the file type filter string, for each version of PowerPoint I'm supporting. This would likely have other issues too...

I'd rather call the native command. Any help appreciated.

Regards

Andrew
Posted 19 Jun, 2008 05:14:59 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Andrew,

You can use the following code to save a presentation:


private void adxCommandBarButton1_Click(object sender)
{
     Microsoft.Office.Core.FileDialog fd = PowerPointApp.get_FileDialog(Microsoft.Office.Core.MsoFileDialogType.msoFileDialogSaveAs);
     fd.Show();
     PowerPointApp.ActivePresentation.SaveAs(fd.SelectedItems.Item(1), Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, Microsoft.Office.Core.MsoTriState.msoTrue);
}
.NET, Extended MAPI, Windows Phone & RT
Posted 19 Jun, 2008 05:54:27 Top
Andrew Bewley




Posts: 7
Joined: 2008-06-19
Hi,

There is no get_FileDialog method on PowerPointApp.

There is a FileDialog method which returns an object of type PowerPoint.FileDialog, however using this I loose the Show method.

I've just created a clean project to double check that my project didn't have some screwed up references, but I get the exact same issue.

Regards

Andy
Posted 19 Jun, 2008 06:27:19 Top
Andrew Bewley




Posts: 7
Joined: 2008-06-19
Hi,

thanks for the response, however...

PowerPointApp doesn't have a get_FileDialog method...

If a reference the Microsoft.Office.Interop.PowerPoint (v12.0.0.0) assembly, it does exist in there, but the Interop.PowerPoint assembly which was added as part of the Addin Express project doesn't.

Surely I don't have to reference additional PIA's?
If so, I'm having to support Office XP/2003/2007, would I have to reference the PIA's for the lowest common denominator (XP).

Regards

Andrew
Posted 19 Jun, 2008 06:40:54 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Andrew,

Above I listed a sample code for a version specific add-in. You can use the following code for a version neutral add-in:


PowerPoint.FileDialog fd = PowerPointApp.FileDialog(PowerPoint.PpFileDialogType.ppFileDialogSave);
fd.Launch(null);
PowerPointApp.ActivePresentation.SaveAs(fd.Files.Item(1),PowerPoint.PpSaveAsFileType.ppSaveAsPresentation,Office.MsoTriState.msoTrue);
.NET, Extended MAPI, Windows Phone & RT
Posted 19 Jun, 2008 07:07:11 Top
Andrew Bewley




Posts: 7
Joined: 2008-06-19
Hi,

I get an InvalidCastException thrown on the first line.
i.e. PowerPoint.FileDialog fd = PowerPointApp.FileDialog(PowerPoint.PpFileDialogType.ppFileDialogSave);

I tried...

Object obj = PowerPointApp.FileDialog(PowerPoint.PpFileDialogType.ppFileDialogSave);

and still get the exception.

Odd!?!?!?

Heres's the exception detail.
System.InvalidCastException was unhandled by user code
Message="Specified cast is not valid."
Source="Interop.PowerPoint"
StackTrace:
at PowerPoint._Application.FileDialog(PpFileDialogType Type)
at MyAddin2.AddinModule.adxRibbonButton1_OnClick(Object sender, IRibbonControl control, Boolean pressed) in D:\Development\User Apps\MyAddin2\MyAddin2\AddinModule.cs:line 99
at AddinExpress.MSO.ADXRibbonButton.DoInternalAction(ADXRibbonOnActionEventArgs e)
InnerException:
Posted 19 Jun, 2008 08:10:37 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Andrew,

Excuse me, I checked it in Outlook 2003. Unfortunately, Outlook 2000 doesn't have the FileDialog class. Please use the following code:


            System.Windows.Forms.SaveFileDialog fd = new System.Windows.Forms.SaveFileDialog();
            if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                PowerPointApp.ActivePresentation.SaveAs(fd.FileName, PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, Office.MsoTriState.msoTrue);
            }
.NET, Extended MAPI, Windows Phone & RT
Posted 19 Jun, 2008 11:01:00 Top
Andrew Bewley




Posts: 7
Joined: 2008-06-19
Hi,

I've been down this avenue. If I do this, I loose the ability to select the file type extension.

As I stated in the original post, I'd have to populate the filter list manually for each variant of the application (i.e. XP/2003/2007) then when calling the SaveAs method try and figure out the correct setting for the FileFormat property.

Are we saying that there is no way to control the functionallity via the interface? Is this because its using the 2000(XP) PIA's? If I dropped support for XP could I upgrade the PIA version and gain the functionallity?

Regards




Posted 19 Jun, 2008 11:36:52 Top
Andrei Smolin


Add-in Express team


Posts: 16334
Joined: 2006-05-11
Hi Andrew,

If you use a non-Office file dialog, then you need to populate its properties yourself. You can check the HostVersion property of the add-in module in order to change file formats in the the dialog.

But if you use the built-in FileDialog, it does these preparations for you. FileDialog was introduced in Office XP. I don't understand why you can't see the Show method. Choose "Use Primary Interop Assemblies" flag while creating a COM add-in project on a PC with Office XP installed.

Regards from Belarus (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 20 Jun, 2008 06:53:20 Top
Andrew Bewley




Posts: 7
Joined: 2008-06-19
Hi,

The idea of doing all the dialog definition doesn't fill me with desire ;)
Tieing the selected file type to the appropriate FileFormat property seems like a high risk.

I've created the addin on a machine hosting Office 2007. Thus far I've only performed testing on 2007+2003.

When I created my Add-In I selected 'Use Version-neutral Office PIAs'.
Is this where I've gone wrong?

If I create an Add-In, deselecting this option and build it using the XP PIAs, this will give me access to the Show method?

Regards
Andy
Posted 20 Jun, 2008 09:58:58 Top