Hyperlink

This article demonstrates adding, accessing, removing, and updating hyperlinks on shapes using Aspose.Slides for .NET.

Copy a C# block into Program.cs in a .NET project with Aspose.Slides.NET6.CrossPlatform installed. Each block is a complete program. Run one block at a time. The ZIP contains the IDE-ready project and its verification checks. The copied code runs in evaluation mode. For licensed output, apply your license before creating a presentation, as described in the licensing guide.

Download and run

Download the complete project, extract it, and open Example.sln or run:

dotnet restore Example.sln
dotnet run --project Example.csproj -- --mode evaluation

The download includes every case below, its fixture helpers and inputs. Program.cs runs all cases; use --action block-001 to run one independently. Outputs and an action report are written to the printed output directory. No previous example or working-directory setup is required. Evaluation adds a watermark and can truncate read-back text; the short fixtures still have explicit structural checks. For full text and no watermark, use --mode licensed --license PATH with your own valid license. See the setup guide for supported SDKs and native prerequisites.

Create a hyperlink on the text portion inside a rectangle shape.

using Aspose.Slides.Export;
using Aspose.Slides;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 150, 50);
shape.TextFrame.Text = "Aspose";

var textPortion = shape.TextFrame.Paragraphs[0].Portions[0];
textPortion.PortionFormat.HyperlinkClick = new Hyperlink("https://www.aspose.com");

presentation.Save("hyperlink-01.pptx", SaveFormat.Pptx);

Read hyperlink information from a shape’s text portion.

using System;
using Aspose.Slides.Export;
using Aspose.Slides;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 150, 50);
shape.TextFrame.Text = "Aspose";

var textPortion = shape.TextFrame.Paragraphs[0].Portions[0];
var portionFormat = textPortion.PortionFormat;
portionFormat.HyperlinkClick = new Hyperlink("https://www.aspose.com");

var hyperlink = portionFormat.HyperlinkClick;
Console.WriteLine(hyperlink.ExternalUrl);

presentation.Save("hyperlink-02.pptx", SaveFormat.Pptx);

Clear the hyperlink from a shape’s text.

using Aspose.Slides.Export;
using Aspose.Slides;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 150, 50);
shape.TextFrame.Text = "Aspose";

var textPortion = shape.TextFrame.Paragraphs[0].Portions[0];
var portionFormat = textPortion.PortionFormat;
portionFormat.HyperlinkClick = new Hyperlink("https://www.aspose.com");

portionFormat.HyperlinkClick = null;

presentation.Save("hyperlink-03.pptx", SaveFormat.Pptx);

Change the target of an existing hyperlink. Use HyperlinkManager to modify text that already contains a hyperlink, which mimics how PowerPoint updates hyperlinks safely.

using Aspose.Slides.Export;
using Aspose.Slides;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 150, 50);
shape.TextFrame.Text = "Aspose";

var textPortion = shape.TextFrame.Paragraphs[0].Portions[0];
textPortion.PortionFormat.HyperlinkClick = new Hyperlink("https://old.example.com");

// Update the target of the existing text hyperlink through its manager.
textPortion.PortionFormat.HyperlinkManager.SetExternalHyperlinkClick("https://new.example.com");

presentation.Save("hyperlink-04.pptx", SaveFormat.Pptx);