We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to replace hyperlink in Slides?

I can able to retrieve the hyperlinks from the Slides.Now I need to replace the old link with new link.


I used the below approach to replace the links

Presentation pres = new Presentation(objMemory);

List HypLinks = new List();

foreach (ISlide slide in pres.Slides)
{
//Get an Array of TextFrame objects from the first slide
ITextFrame[] textFramesSlideOne = Aspose.Slides.Util.SlideUtil.GetAllTextBoxes(slide);

//Loop through the Array of TextFrames
for (int i = 0; i < textFramesSlideOne.Length; i++)

//Loop through paragraphs in current TextFrame
foreach (Aspose.Slides.Paragraph para in textFramesSlideOne[i].Paragraphs)

//Loop through portions in the current Paragraph
foreach (Portion port in para.Portions)
{
if (port.PortionFormat.AsIHyperlinkContainer.HyperlinkClick != null)
{
if (port.PortionFormat.AsIHyperlinkContainer.HyperlinkClick.ExternalUrl == OldLink)
{
HypLinks.Add(port.PortionFormat.AsIHyperlinkContainer.HyperlinkClick.ExternalUrl);
port.PortionFormat.HyperlinkManager.SetExternalHyperlinkClick(NewLink);
iLlinksUpdated++;
}
}
}
}

Though it’s working, the performance seems to be slower.

Regards,
David.

Hi David,

I have observed the code sample shared by you and it seems perfectly fine. The performance of the above code depends on amount of text in your presentation. You are actually traversing through every slide shape and for every shape with text, you are extracting the text on portion level by continuous looping. The performance here depends on content inside presentation. I have seen your other post where you have shared the code in which you are extracting the hyperlink list on slide level. This would save your continuous looping inside every shape paragraphs and portions in order to locate hyperlink and doing the replacement. Therefore, using the code in your other post, you can do the replacement certainly with much better performance.

Many Thanks,