1

I am working on an app that will allow the user to upload a presentation, edit it, and then download the final output as another PowerPoint presentation.

I have very unstable behavior for different presentations that I upload:

  1. Sometimes the changed images are blurred (Not sure why?)

  2. Sometimes incorrect shape ids are returned, and therefore I can not merge the changed work with the existing PowerPoint shape.

    var shape = (PowerPoint.Shape)item;
    var shapeid=shape.ID; //this is different from what interop has returned on first presentation read.
    
  3. Animations are not getting copied properly(sometimes they do sometimes they do not).

          newshape.AnimationSettings.EntryEffect = oldshape.AnimationSettings.EntryEffect;
          newshape.AnimationSettings.AdvanceMode=oldshape.AnimationSettings.AdvanceMode;        
          newshape.AnimationSettings.AdvanceTime=oldshape.AnimationSettings.AdvanceTime;
          newshape.AnimationSettings.AfterEffect=oldshape.AnimationSettings.AfterEffect;
          newshape.AnimationSettings.Animate=oldshape.AnimationSettings.Animate;
          newshape.AnimationSettings.AnimateBackground = oldshape.AnimationSettings.AnimateBackground;
          newshape.AnimationSettings.TextLevelEffect = PowerPoint.PpTextLevelEffect.ppAnimateByAllLevels;
          newshape.AnimationSettings.AnimateTextInReverse=oldshape.AnimationSettings.AnimateTextInReverse;
    

I am aware of the fact that server side automation may have unstable behavior or deadlock. However nothing documents exactly what is unstable about the behavior.
Are these behaviors (above two) in same category or am I missing something here? How can I fix these issues?

Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
  • 3
    "Unstable Office Automation" is a tautology :( – Joel Coehoorn Mar 19 '14 at 14:24
  • I think we'll need to see more of what your code is doing to point out potential fixes. – Joel Coehoorn Mar 19 '14 at 14:28
  • @JoelCoehoorn: Thanks for edit.as i have already mentioned about many unstable behaviour i came across. I will even add the part that copies animation from existing shape to newly created shape. – Milind Anantwar Mar 19 '14 at 14:30
  • 4
    It is a horrible idea to use Office Interop from ASP.NET or another server technology. These APIs were written for use in a desktop application, for automating Office (a suite of desktop applications). Server applications are different in many ways that make it a very, very bad idea to use Office Interop in them. It's also unsupported by Microsoft, and may violate your Office license. See [Considerations for server-side Automation of Office](http://support.microsoft.com/kb/257757) – John Saunders Mar 19 '14 at 14:30
  • @JohnSaunders : what should be the correct way of implementing Office automation then. I could see everywhere developers talking about its instability. But could not found the alternatives for same. – Milind Anantwar Mar 19 '14 at 14:41
  • Then if you know it is unstable, why are you trying to use it? Only use Office Automation in a desktop application. Otherwise, use a product like the Aspose products. – John Saunders Mar 19 '14 at 14:42
  • @JohnSaunders : well we have a requirement in here and we need to get it rolling. – Milind Anantwar Mar 19 '14 at 14:46
  • 3
    Unless you have a requirement for your application to be an unstable piece of garbage, I suggest you stop rolling in the direction of using Office Interop from server applications. Microsoft already told you "no", and you've seen it "everywhere", so what does it take to make you realize you made a bad mistake? – John Saunders Mar 19 '14 at 14:48

1 Answers1

-1

If you still need to use Interop then try to release the COM objects and ocasionally kill the PowerPoint instances as mentioned below:

public static class PowerPointInterOp
{
    static PowerPoint.Application powerPointApp = null;
    static Object oMissing = System.Reflection.Missing.Value;
    static Object oTrue = true;
    static Object oFalse = false;
    static Object oCopies = 1;

    public static void InitializeInstance()
    {
        if (powerPointApp == null)
        {
            powerPointApp = new PowerPoint.ApplicationClass();

        }           
    }

    public static void KillInstances()
    {
        try
        {
            Process[] processes = Process.GetProcessesByName("POWERPNT");
            foreach(Process process in processes)
            {
                process.Kill();
            }
        }
        catch(Exception)
        {

        }
    }

    public static void CloseInstance()
    {
        if (powerPointApp != null)
        {
            powerPointApp.Quit();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(powerPointApp);
            powerPointApp = null;
        }
    }

    public static PowerPoint.Presentation OpenDocument(string documentPath)
    {
        InitializeInstance();

        PowerPoint.Presentation powerPointDoc = powerPointApp.Presentations.Open(documentPath, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse);

        return powerPointDoc;
    }

    public static void CloseDocument(PowerPoint.Presentation powerPointDoc)
    {
        if (powerPointDoc != null)
        {
            powerPointDoc.Close();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(powerPointDoc);
            powerPointDoc = null;
        }           
    }


}
Satya
  • 1
  • 1