Solved

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

Posted on 2016-09-23
2
85 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
  • 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
combine fist two words in a cell 2 25
HELP WITH  INDEX MATCH to look from LEFT TO RIGTH 4 14
vba to flip column 14 23
Excel 2010 - SUMIF with and AND 2 8
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
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…

820 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