PowerPoint 2010 convert old ppt file to 2010 with embedded media with .net c# RRS feed

  • Question

  • I am fighting a long time with the PowerPoint API and got stuck ...

    I am using Visual Studio 2010 with C#, Office 2010 installed and need to convert ppt Files to 2010 format programmatically.

    How can i resolve the version of a powerpoint file? not by the extension, cause there are some people that rename the extension from pptx to ppt and vice versa

    I did not find any property that tells me i am old 97-2000 format or 2007 without embedded files or 2010 with embedded files.

    Next question:

    How can i convert or upgrade a powerpoint file from an old version to the new one with embedding all media objects?

    In a folder i have a old .ppt file with some videos and the videos are stored in the same folder.

    The Convert2 Method always throws an exception.

    EnsureAllMediaUpgraded works for some time but doesnt change anything.

    If i remove the video objects and add them as embedded again as work around any other information (animations and click events) are lost.

    That is the last question:

    I did not find a way to read/write all animations and effects of a shape.

    I think the powerpoint api does not support full functionallity like the gui.

    Or am i wrong? Can anyone tell me how to do that?

    Wednesday, September 19, 2012 2:10 PM

All replies

  • Hi NGZero,

    Thanks for posting in the MSDN Forum.

    How can i resolve the version of a powerpoint file? not by the extension, cause there are some people that rename the extension from pptx to ppt and vice versa

    I think we needn't pay attention on this issue. In PowerPoint2010 will works fine with ".ppt" and ".pptx" entension.

    How can i convert or upgrade a powerpoint file from an old version to the new one with embedding all media objects?

    Would you please use saveas method?

    I would recommend your share your code in the post for further trouble shooting, it will let community members easier to understand what you want.

    Have a good day,


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, September 20, 2012 8:51 AM
  • Thanks for your answer. I will explain in more in detail.
    I wrote a program for a media check. Speakers for medical congresses come to us and commit their presentation.
    The program has to check the file so that all content will be correct displayed on the projector and all media objects (video/sound) will work fine.
    Then the presentation will be delivered via network to the right room and be played on the right time slot.

    In my case i have to work with PowerPoint files from any version (97/2000/2003/2007/2010) and any program (MS PPT, Mac, OpenOffice).
    I noticed that there are some PowerPoint Objects like msoMedia, msoPlaceholder and so on that have not always the same properties accessible.
    Sometimes i have a ppt file with a video in it (Type = MsoShapeType.msoMedia and MediaType = PpMediaType.ppMediaTypeMovie) and Shape.MediaFormat is accessbile and sometimes an exception will occur.
    Sometimes the Shape.AnimationSettings.PlaySettings can be readed and sometimes an excpetion will occur and so on.
    Depending on the program that the ppt created the available properties will differ extremely from a solid base.

    So in fact of that, i want to convert all files at first to the actual pptx format, so that all accessible properties are on the same version and therefore useable.
    If i use the SaveAs-Method the ppt will be converted to pptx. That works well.

    But the next problem is that there are presentations that have hundreds of videos in it. If there are hundreds of videos in the same folder it is not so easy to handle 101 small files against only 1 big.
    There is also another problem. If i have a pptx with embedded media objects i can read the playtime of the video/sound file.
    We also have an application called ePoster (self service terminal) that opens PowerPoint files and automatically changes slides and plays videos.
    So i need the video play length to get the total amout of how long the slide should be displayed that the slide will not be skipped while the video is still playing.
    In some cases i can play or even not videos that are not embedded. videos that are embedded can always be controlled programmatically.

    So... how to embed videos from old powerpoint files that lie in the same folder as the presentation???
    To get 1 powerpoint file with no matter how much multimedia objects and the ability to easily read the playtime of each object??

    If i save the following old files to pptx no video will be embedded:
    PowerPoint 97 .ppt File
    PowerPoint 2000 .ppt File
    But if i open them not programmatically assort manually by powerpoint gui i can convet the file in the backstage menu and all media will be embedded.

    These files will embed the videos in one pptx file by saving with PIA:
    PowerPoint 2007 .ppt File compatible 97/2000
    PowerPoint 2010 .ppt File compatible 97/2000

    The last problem of old powerpoint files are sometimes that in Shape.LinkFormat.SourceFullName stands a full path to the video file even if the videos lie in the same folder as the presentation.
    If i copy this presentation to another system powerpoint tell me that it cant find the source.

    In some presentations i can change the SourceFullName but in some presentations an exception is thown and i can not change the value.

    One workaround would be to remove old video files and add them again with the flag to embed it.
    That works fine but then all animations and effect will be lost.
    I can not access all animations and effects like you can do in the PPT GUI by the PIA.

    Also another "bug" is that if i have a msoTextbox or msoPlaceholder i can access the Text but not the rtf code behind. so if i have a textbox with different colors and styles in it and i replace the text all formatting will be lost.

    In my mind the office especial the powerpoint pia is not maked with love. its just that no one cry about missing interopability.
    Thursday, September 20, 2012 12:07 PM
  • With this i access the powerpoint files and convert them to pptx.

    PowerPoint and Office   PIA Version 14

    public static FileWrapper Open(string path) { diagnostic.Logger.Debug("ecs.core.presentation.PowerPoint.Wrapper :: Open :: BEGIN"); var returnValue = new FileWrapper(); if (!File.Exists(path)) { diagnostic.Logger.Debug("ecs.core.presentation.PowerPoint.Wrapper :: Open :: END (path not exists)"); return null; } if (!io.FileHelper.FileCanWrite(path, true)) { diagnostic.Logger.Debug("ecs.core.presentation.PowerPoint.Wrapper :: Open :: END (file open)"); return null; } var fs = new FileStream(path, FileMode.Open, FileAccess.Read); try {

    // check if the file is pptx/zip or not. var file = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(fs); file.GetNextEntry(); fs.Close(); if (Path.GetExtension(path) != ".pptx") { var oldPath = path; path = Path.ChangeExtension(path, ".pptx"); File.Move(oldPath, path); } } catch (Exception) {

    // No pptx file / zip file, so i have to convert fs.Close(); var oldPath = Path.ChangeExtension(path, ".old" + Path.GetExtension(path)); File.Move(path, oldPath); path = Path.ChangeExtension(path, ".pptx"); returnValue.ComInstance = Constants.PPApplication.Presentations.Open2007(oldPath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoTrue); returnValue.ComInstance.SaveAs(path, PPT.PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoTrue); returnValue.ComInstance.Close(); } finally {

    // Finally open the correct pptx file returnValue.ComInstance = Constants.PPApplication.Presentations.Open2007(path, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); returnValue.PresentationPath = path; returnValue.Name = returnValue.ComInstance.Name; returnValue.FirstSlideNumber = returnValue.ComInstance.PageSetup.FirstSlideNumber; returnValue.SlidesHeight = (int)returnValue.ComInstance.PageSetup.SlideHeight; returnValue.SlidesWidth = (int)returnValue.ComInstance.PageSetup.SlideWidth; } diagnostic.Logger.Debug("ecs.core.presentation.PowerPoint.Wrapper :: Open :: END"); return returnValue; }

    public void Save()
                public void Close()

    • Edited by NGZero Thursday, September 20, 2012 12:13 PM comments
    Thursday, September 20, 2012 12:11 PM
  • Hi NGZero,

    OK, I think your issue is beyond my ability. I will involve some experts into your issue. Let's see whether they can solve your issue. There might be some time delay, thanks for your patience.

    Have a good day,


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, September 24, 2012 6:12 AM
  • Hello NGZero,

    You can either use System.IO.Packaging.Package class or using System.IO.BinaryReader class to check if the file is an Open XML format (PPTX) or Binary (PPT) format.

    All the (non-corrupted) Open XML format files (PPTX, XLSX, DOCX etc) starts its first two bytes with the characters 'P' and 'K'.

    Using the code given below, you can check if the file is a PPTX or PPT.

    System.IO.BinaryReader br = new System.IO.BinaryReader(System.IO.File.Open("<fileName>", System.IO.FileMode.Open));
    byte[] b = br.ReadBytes(2);
    if((char)b[0] == 'P' && (char)b[1]== 'K')
      MessageBox.Show("PPTX file");

    The Open XML files are Packages - a group of XML files packaged together. Those files can be easily opened using System.IO.Packaging.Package class.

    The following code will throw an exception if you try to open a PPT file:

    Package pkg = System.IO.Packaging.Package.Open(fileName);

    After checking the file format, you can convert the file to either format using Presentation.SaveAs() method and specifying the format. For more information on SaveAs() method, please visit the following link:


    Sreerenj G Nair

    Monday, October 8, 2012 5:08 PM