Welcome to OpenXML Developer Sign in | Join | Help

How to convert a pptx file to ppt in C#

Last post 07-02-2008, 5:17 PM by minatopenxml. 5 replies.
Sort Posts: Previous Next
  •  06-02-2008, 2:30 AM 3280

    How to convert a pptx file to ppt in C#

    Hi guys.
    I have got a .pptx file. But I want the same content in the .ppt format. Is there a way to achieve this using C# .

    Thanks in Advance
    con.

  •  06-05-2008, 2:34 AM 3303 in reply to 3302

    Re: How to convert a pptx file to ppt in C#

    Thanks for the reply..
    But all these links provide us with the service of uploading a pptx file to their server and they are doing the conversion for us. I want to do the conversion in my system itself (mainly due to security reasons and application stability.). I have got a sample application in C#. But it dont know its exact usage(basically I am not a C# guy.!!!!). The method demands three arguments(The third being something regarding to font). But I cannot exactly understand its usage. In the sample application I found only two args and the program is not working because of argument mismatch.

    Below is the code. can you fix it without changing the font or layout of the actual pptx.

    using System;
    using System.Collections.Generic;
    using System.Text;
    using PowerPoint = Microsoft.Office.Interop.PowerPoint;
    using Microsoft.Office.Core;

    namespace ConsoleApplication5
    {
        class Program
        {
            static void Main(string[] args)
            {
                PowerPoint.Application app = new PowerPoint.Application();
                string sourcePptx = @"c:\test.pptx";
                string targetPpt = @"c:\test.ppt";
                object missing = Type.Missing;
                PowerPoint.Presentation pptx = app.Presentations.Open(sourcePptx, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoTrue);
                pptx.SaveAs(targetPpt, PowerPoint.PpSaveAsFileType.ppSaveAsPowerPoint4);
                app.Quit();
            }
        }
    }

    Thanks in advance..
    Expecting your reply
    con



  •  06-06-2008, 12:52 AM 3309 in reply to 3303

    Re: How to convert a pptx file to ppt in C#

    Hi,
    Try doing PowerPoint.PpSaveAsFileType.ppSaveAsPresentation(not ppSaveAsPowerPoint4).
    Change last two lines and try agin.I hope it will work fine.

    PowerPoint.Presentation pptx = app.Presentations.Open(sourcePptx, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoFalse);
    pptx.SaveAs(targetPpt, PowerPoint.PpSaveAsFileType.ppSaveAsPresentation,MsoTriState.msoTrue);
    app.Quit();

    Mallika

  •  06-06-2008, 8:10 AM 3312 in reply to 3309

    Re: How to convert a pptx file to ppt in C#

    Thanks Mallik.
    Now its working fine. I changed the code just as you have mentioned.
    Thanks Again
  •  07-02-2008, 5:17 PM 3435 in reply to 3309

    Re: How to convert a pptx file to ppt in C#

    Hi,

    That's very helpful!

    The only problem I have is that if I already have a PowerPoint app open, the moment

    app.Quit();

    is called, the previously opened PP will be closed silently, not give me a chance to save unsaved ppt. Is there a way to avoid that while saving pptx as ppt?

    For example, can I check if there's already a PowerPoint app open? or Is there a way to just close the file (as opposite to quit app) if there's already a PP app open?

    Thanks in advance.

    Min
View as RSS news feed in XML