Hi,
This is my code :

Microsoft.Office.Interop.PowerPoint.Application application = new Microsoft.Office.Interop.PowerPoint.Application();
                string filePath = Server.MapPath(@"~\\Staf\\TestDoc\\" + strFileName.ToString());
                Microsoft.Office.Interop.PowerPoint.Presentation pptPresentation = application.Presentations.Open(filePath, 
                    Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, 
                    Microsoft.Office.Core.MsoTriState.msoFalse);
                application.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;

                StringBuilder sb = new StringBuilder();
                int page = pptPresentation.Slides.Count;
                for (int num = 1; num < page + 1; num++)
                {
                    Microsoft.Office.Interop.PowerPoint.Shapes slide = pptPresentation.Slides[num].Shapes;
                    //loop through all the shapes
                    foreach (Microsoft.Office.Interop.PowerPoint.Shape s in slide)
                    {
                        // Check to see if shape has a text frame and text
                        if (s.HasTextFrame == MsoTriState.msoTrue && s.TextFrame.HasText == MsoTriState.msoTrue)
                        {
                            if (s.Type.Equals(MsoShapeType.msoPlaceholder))
                            {
                                switch (s.PlaceholderFormat.Type)
                                {
                                    case PpPlaceholderType.ppPlaceholderTitle:
                                        sb.Append(s.TextFrame.TextRange.Text);
                                        sb.Append(Environment.NewLine);
                                        break;
                                    case PpPlaceholderType.ppPlaceholderCenterTitle:
                                        sb.Append(s.TextFrame.TextRange.Text);
                                        sb.Append(Environment.NewLine);
                                        break;
                                    case PpPlaceholderType.ppPlaceholderBody:
                                        sb.Append(s.TextFrame.TextRange.Text);
                                        sb.Append(Environment.NewLine);
                                        break;
                                    case PpPlaceholderType.ppPlaceholderSubtitle:
                                        sb.Append(s.TextFrame.TextRange.Text);
                                        sb.Append(Environment.NewLine);
                                        break;
                                    case PpPlaceholderType.ppPlaceholderFooter:
                                        sb.Append(s.TextFrame.TextRange.Text);
                                        sb.Append(Environment.NewLine);
                                        break;
                                    case PpPlaceholderType.ppPlaceholderHeader:
                                        sb.Append(s.TextFrame.TextRange.Text);
                                        sb.Append(Environment.NewLine);
                                        break;
                                    default:
                                        // don't need anything else
                                        break;
                                }
                            }
                        }
                    }
                }
                string text = sb.ToString();

                 // Close word.
                pptPresentation.Close();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pptPresentation);
                //wordApp.Application.Quit();

with my code, i can't read content of slide 2, 3, etc..
its just read slide 1 and all title of the ppt file. Whats wrong? What should i do?

thx,

Dani AI

Generated

This problem is almost always caused by only reading placeholder text and not every text container on a slide. As suggested, filtering by specific placeholder types will skip many shapes that contain text (textboxes, table cells, grouped shapes, notes, SmartArt/OLE/chart titles, etc.). The fix is to extract text from every shape that actually holds text and to recurse into group items and table cells.

Checklist (quick fixes to try)

  • Stop restricting to placeholder types; treat any shape with a text frame as a candidate.
  • Check both TextFrame and TextFrame2 (some newer content lives in TextFrame2).
  • Recursively iterate GroupItems when s.Type == msoGroup.
  • If s.HasTable == msoTrue iterate table rows/cells and read each cell’s Shape.TextFrame.TextRange.Text.
  • Read slide notes via slide.NotesPage.Shapes.
  • Log shape.Type, HasTextFrame, HasTable, PlaceholderFormat.Type while debugging to see what you’re skipping.

Example extraction pattern (safely different from the original snippet)

void AppendShapeText(Microsoft.Office.Interop.PowerPoint.Shape s, StringBuilder sb)
{
    if (s == null) return;

    if (s.Type == Microsoft.Office.Core.MsoShapeType.msoGroup)
    {
        foreach (Microsoft.Office.Interop.PowerPoint.Shape g in s.GroupItems)
            AppendShapeText(g, sb);
        return;
    }

    if (s.HasTable == Microsoft.Office.Core.MsoTriState.msoTrue)
    {
        var tbl = s.Table;
        for (int r = 1; r <= tbl.Rows.Count; r++)
            for (int c = 1; c <= tbl.Columns.Count; c++)
                sb.AppendLine(tbl.Cell(r, c).Shape.TextFrame.TextRange.Text.Trim());
        return;
    }

    if (s.HasTextFrame == Microsoft.Office.Core.MsoTriState.msoTrue &&
        s.TextFrame.HasText == Microsoft.Office.Core.MsoTriState.msoTrue)
    {
        sb.AppendLine(s.TextFrame.TextRange.Text.Trim());
        return;
    }

    // fallback: try TextFrame2
    try
    {
        var t2 = s.TextFrame2.TextRange.Text;
        if (!string.IsNullOrWhiteSpace(t2)) sb.AppendLine(t2.Trim());
    }
    catch { }
}

Caveats and final notes

  • Always release COM objects (presentation, slides, shapes, application) in finally blocks and call application.Quit(); use Marshal.ReleaseComObject and GC.Collect/WaitForPendingFinalizers.
  • Office Interop on a web server is fragile and not supported for unattended server automation; for server-side extraction consider Open XML SDK or a dedicated library (e.g., Aspose.Slides or a PowerPoint-specific API) for reliability and scalability.

Thank you for posting code...
i see that you used a switch statement that will process the flow "default" if the type placeholderformat is out of control...and this causes the problem because when the type is ppPlaceholderObject as an example;it wont add the the texframe range text to stringbuilder.i suggest you to remove switch control and use your code.let me know if helped...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.