Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2016-09-23
2
Medium Priority
?
147 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

715 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