Articles in this section
Category / Section

How to replace the hyperlink within a SmartArt in ASP.NET Core PowerPoint Presentation?

3 mins read

Syncfusion Presentation is a .NET PowerPoint Library used to create, read, edit and convert PowerPoint files to PDF and images programmatically without Microsoft Office or interop dependencies. Using this library, you can replace the hyperlink within a SmartArt in PowerPoint Presentation using C#.

Steps to replace the hyperlink within a SmartArt in PowerPoint using C#

  1. Create a new C# Console application project
    Console application in Visual Studio
  2. Install the Syncfusion.Presentation.Net.Core NuGet package as a reference to your project from Nuget.org.
    Install Presentation NuGet

Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering a Syncfusion license key in your application to use the components without trail message.

  1. Include the following namespace in the Program.cs file.
    C#
using Syncfusion.Presentation;
  1. Use the following code snippet to replace the hyperlink inside a SmartArt.
    C#
FileStream stream = new FileStream("Input.pptx", FileMode.Open, FileAccess.Read);
IPresentation pptxDoc = Presentation.Open(stream);
//Hyperlinks to find
string findText1 = "www.xyz.com";
string findText2 = "www.abcd.com";
string findText3 = "www.123.com";
//Get the slide
ISlide slide = pptxDoc.Slides[0];
//Replace the Hyperlink with another hyperlink
ReplaceHyperlink(slide, findText1);
ReplaceHyperlink(slide, findText2);
ReplaceHyperlink(slide, findText3);
//Save the output
FileStream output = new FileStream("Output.pptx", FileMode.Create, FileAccess.Write);
pptxDoc.Save(output);
pptxDoc.Close(); 
  1. Use the following method to find and replace the hyperlink inside a SmartArt.
    C#
//Replace the hyperlink with another hyperlink
public void ReplaceHyperlink(ISlide slide, string findText)
{
   //Replacement Hyperlink
   string replaceText = "www.syncfusion.com";
   //Find the hyperlink from the slide
   ITextSelection[] textSelections = slide.FindAll(findText, true, false);
   if (textSelections != null)
   {
       //Iterate through the textselection
       for (int i = 0; i < textSelections.Length; i++)
       {
           //Get the each textselection as one TextPart
           ITextPart textPart = textSelections[i].GetAsOneTextPart() as ITextPart;
           //Replace the hyperlink text
           textPart.Text = replaceText;
           //Set the new hyperlink
           textPart.SetHyperlink(replaceText);
       }
   }
}

You can download a complete working sample from GitHub.

Take a moment to peruse the documentation, where you can find basic presentation document processing options along with features like clone and merge slides and encrypt and decrypt PowerPoint presentation and most importantly PDF and image conversion with code examples.

Explore more about the rich set of Syncfusion PowerPoint Framework features.

Conclusion

I hope you enjoyed learning how to replace hyperlink inside a SmartArt in PPTX using C#.

You can refer to our .NET PowerPoint Library feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied