Open and read PowerPoint files in C# and VB.NET

With GemBox.Presentation you can open and read different PowerPoint file formats (like PPTX and PPT) in the same manner. The presentations can be loaded using one of the PresentationDocument.Load methods from your C# and VB.NET application. These methods enable you to work with a physical file (when providing the file's path) or with an in-memory file (when providing the file's Stream).

You can specify the format of your PowerPoint file by providing an object from the LoadOptions derived class (like PptxLoadOptions and PptLoadOptions). Or you can let GemBox.Presentation choose the appropriate options for you when opening the file by omitting the LoadOptions.

The following example shows how you can read a presentation, iterate over all Shape, TextParagraph and TextRun elements within, and display text and font-weight information for all TextRun elements.

Opening and reading PowerPoint presentation's shapes and text in C# and VB.NET
Screenshot of read shapes and text from input PowerPoint presentation
Upload your file (Drag file here)
using GemBox.Presentation;
using System;
using System.Linq;
using System.Text;

class Program
    static void Main()
        // If using the Professional version, put your serial key below.

        var presentation = PresentationDocument.Load("%InputFileName%");

        var sb = new StringBuilder();

        var slide = presentation.Slides[0];

        foreach (var shape in slide.Content.Drawings.OfType<Shape>())
            sb.AppendFormat("Shape ShapeType={0}:", shape.ShapeType);

            foreach (var paragraph in shape.Text.Paragraphs)
                foreach (var run in paragraph.Elements.OfType<TextRun>())
                    var isBold = run.Format.Bold;
                    var text = run.Text;

                    sb.AppendFormat("{0}{1}{2}", isBold ? "<b>" : "", text, isBold ? "</b>" : "");



Imports GemBox.Presentation
Imports System
Imports System.Linq
Imports System.Text

Module Program

    Sub Main()

        ' If using the Professional version, put your serial key below.

        Dim presentation = PresentationDocument.Load("%InputFileName%")

        Dim sb = New StringBuilder()

        Dim slide = presentation.Slides(0)

        For Each shape In slide.Content.Drawings.OfType(Of Shape)

            sb.AppendFormat("Shape ShapeType={0}:", shape.ShapeType)

            For Each paragraph In shape.Text.Paragraphs

                For Each run In paragraph.Elements.OfType(Of TextRun)

                    Dim isBold = run.Format.Bold
                    Dim text = run.Text

                    sb.AppendFormat("{0}{1}{2}", If(isBold, "<b>", ""), text, If(isBold, "</b>", ""))



    End Sub
End Module

See also

Next steps

GemBox.Presentation is a .NET component that enables you to read, write, edit, convert, and print presentation files from your .NET applications using one simple API.

Download Buy