Solved

How to get the title of a presentation of a powerpoint app C#

Posted on 2016-09-23
2
127 Views
Last Modified: 2016-10-12
Hello experts,
My idea is that when I create a presentation a button will be created automatically and when I close it, the button must be removed so I need to get the title of the presentation do you have any idea ?
Here is what I did:
 
using Powerpoint = Microsoft.Office.Interop.PowerPoint;      
Powerpoint.Application wdApp = new Powerpoint.Application();
    string oldCaption = wdApp.Application.Caption ;
    string guid = Guid.NewGuid().ToString();
    //set caption to random value
    wdApp.Application.Caption = guid;
    //create a presentation
    PresentationpptPresentation=wdApp.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue);
    //make sure app is visible:
    wdApp.Visible = true;
    //find random value to get process id
    //here I need to get the title of the presentation
    int processId = GetProcessIdByWindowTitle(guid);

    //reset caption
    wdApp.Application.Caption = oldCaption;

    //create a dictionary
    Dictionary<int, Button> mapping = new Dictionary<int, button>();
    //add mapping
    mapping.Add(new KeyValuePair<int, Button>(processId, deleteButton));







    //found this online:
    /// <summary>
    /// Returns the name of that process given by that title
    /// </summary>
    /// <param name="AppId">Int32MaxValue re
    public static int GetProcessIdByWindowTitle(string AppId)
    {
       Process[] P_CESSES = Process.GetProcesses();
       for (int p_count = 0; p_count < P_CESSES.Length; p_count++)
       {
            if (P_CESSES[p_count].MainWindowTitle.Equals(AppId))
            {
                        return P_CESSES[p_count].Id;
            }
       }

        return Int32.MaxValue;
    }

Open in new window

0
Comment
Question by:SniperCode Sheva
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 18

Accepted Solution

by:
xtermie earned 500 total points (awarded by participants)
ID: 41813458
You can try this code
using System;
using System.Collections.Generic;
using Microsoft.Office.Core;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;

namespace Mintra.Publisher.DocumentConverter.Core.Utils
{
    class InteropUtility
    {


        public static IList<string> GetPresentationTitles(string pptPath)
        {

            IList<string> result = new List<string>();

            var presentationApp = new Microsoft.Office.Interop.PowerPoint.Application();

            try
            {
                presentationApp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
                Microsoft.Office.Interop.PowerPoint.Presentations presentations = presentationApp.Presentations;

                var readOnly = Microsoft.Office.Core.MsoTriState.msoTrue;
                var untitled = Microsoft.Office.Core.MsoTriState.msoTrue;
                var withWindow = Microsoft.Office.Core.MsoTriState.msoFalse;

                Microsoft.Office.Interop.PowerPoint.Presentation presentation = presentations.Open(pptPath, readOnly, untitled, withWindow);
                int i = 0;
                foreach (PowerPoint.Slide slide in presentation.Slides)
                {
                    string defaultTitle = String.Format("Slide {0}", i);
                    String shapeTitle = ExtractSlideTitlefromShape(slide, defaultTitle);
                    result.Add(shapeTitle);
                }
            }
            finally
            {
                presentationApp.Quit();
            }


            return result;

        }

        private static string ExtractSlideTitlefromShape(PowerPoint.Slide slide, string defaultValue)
        {
            PowerPoint.HeadersFooters headersFooters = slide.HeadersFooters;
            PowerPoint.Shapes mastershapes = slide.Master.Shapes;

            for (int i = 1; i <= slide.Shapes.Count; i++)
            {
                PowerPoint.Shape shape = slide.Shapes[i];
                bool hasTextFrame = shape.HasTextFrame == MsoTriState.msoTrue;
                bool isTypePlaceholder = shape.Type.Equals(MsoShapeType.msoPlaceholder);
                bool hasTextInTextFrame = shape.TextFrame.HasText == MsoTriState.msoTrue;
                bool isTitleShape = shape.Name.ToLower().Contains("title");

                if (isTypePlaceholder && hasTextFrame && hasTextInTextFrame && isTitleShape)
                {
                    return shape.TextFrame.TextRange.Text;

                }
            }

            return defaultValue;
        }

    }
}

Open in new window

Or try saving as ppptx and extract titles from the xml that goes with it
0
 
LVL 18

Expert Comment

by:xtermie
ID: 41839770
Solution provided works
0

Featured Post

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of things can happen during a presentation, worst of which is “death by PowerPoint.” Here are a few mistakes to avoid to make your slides clean.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question