How to Link to a Specific Slide in PowerPoint in C#, VB.NET

Hyperlinks in a PowerPoint file not only can be linked to external URLs, but also to the specific slide within the document. This article will show you how to create a hyperlink that links to a specified slide using Spire.Presentation.

Step 1: Create a PowerPoint file and append a slide to it.

Presentation presentation = new Presentation();
presentation.Slides.Append();

Step 2: Add a shape to the second slide.

IAutoShape shape = presentation.Slides[1].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(10, 50, 200, 50));
shape.TextFrame.Text = "Jump to the first slide"; 

Step 3: Create a hyperlink based on the shape and the text on it, linking to the first slide .

ClickHyperlink hyperlink = new ClickHyperlink(presentation.Slides[0]);
shape.Click = hyperlink;
shape.TextFrame.TextRange.ClickAction = hyperlink;

Step 4: Save the file.

presentation.SaveToFile("hyperlink.pptx", FileFormat.Pptx2010);

Output:

How to Link to a Specific Slide in PowerPoint in C#, VB.NET

Full Code:

[C#]
Presentation presentation = new Presentation();
presentation.Slides.Append();
IAutoShape shape = presentation.Slides[1].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(10, 50, 200, 50));
shape.Fill.FillType = FillFormatType.None;
shape.Line.FillType = FillFormatType.None;
shape.TextFrame.Text = "Jump to the first slide";
ClickHyperlink hyperlink = new ClickHyperlink(presentation.Slides[0]);
shape.Click = hyperlink;
shape.TextFrame.TextRange.ClickAction = hyperlink;
presentation.SaveToFile("output.pptx", FileFormat.Pptx2010);
[VB.NET]
Dim presentation As Presentation = New Presentation()
presentation.Slides.Append()
Dim shape As IAutoShape = presentation.Slides(1).Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(10, 50, 200, 50))
shape.Fill.FillType = FillFormatType.None
shape.Line.FillType = FillFormatType.None
shape.TextFrame.Text = "Jump to the first slide"
Dim hyperlink As ClickHyperlink = New ClickHyperlink(presentation.Slides(0))
shape.Click = hyperlink
shape.TextFrame.TextRange.ClickAction = hyperlink
presentation.SaveToFile("output.pptx", FileFormat.Pptx2010)