Hello
I’m tying to check word, excel and powerpoint documents for dead hyperlinks.
Is there any method in Aspose.Word/Slides/Cells that allows me get and iterate all Hyperlinks from a document and replace the dead-links?
Thanks for your help and reagards
Mario
Hi Mario,
Please check the following links to update hyperlinks using Aspose.Words, Aspose.Slides and Aspose.Cells respectively.
http://www.aspose.com/docs/display/wordsnet/How+to++Replace+or+Modify+Hyperlinks
Get all the external hyperlinks in a presentation
http://www.aspose.com/docs/display/cellsnet/Editing+Hyperlinks+of+Worksheet
Best Regards,
Hello Muhammad
Thanks for your answer.
Your Solution has worked for Word and Excel, but it does not work with PowerPoint Presentations.
Here is my CodE:
foreach (var slide in presentation.Slides)
{
try
{
var hyperLinks = slide.HyperlinkQueries.GetAnyHyperlinks();
foreach (var hyperLink in hyperLinks)
{
try
{
var newHyperLink = LinkReplace.CheckHyperlink(hyperLink.HyperlinkClick.ExternalUrl);
if (newHyperLink != null)
{
hyperLink.HyperlinkManager.SetExternalHyperlinkClick(newHyperLink);
hyperLink.HyperlinkManager.SetExternalHyperlinkMouseOver(newHyperLink);
}
}
catch (Exception ex)
{
//ignore
}
}
}
catch (Exception ex)
{
//ignore
}
Here is the exception:
- $exception {“Value does not fall within the expected range.”} System.Exception {System.ArgumentException}
StackTrace " at Aspose.Slides.HyperlinkQueries.(Object , )\r\n at Aspose.Slides.HyperlinkQueries.(Object , )\r\n at Aspose.Slides.HyperlinkQueries.GetAnyHyperlinks()\r\n at CH.ZKB.LIEWG.AsposeApi.Hyperlinks.HyperlinksSlides.ReplaceHyperlinks(Presentation presentation, String oldExtension, String newExtension) in d:\Projects\CH.ZKB.LIEWG.AsposeAPI\CH.ZKB.LIEWG.AsposeAPI\Hyperlinks\HyperlinksSlides.cs:line 22" string
Regards
Mario
Hi Mario,
Thank you for your interest in Aspose.Slides.
I have observed your comments and like to request you to please try using following sample code on your end and then share your kind feedback with us. Also, I have attached the source and generated presentation for your kind reference.
Presentation pres = new Presentation(@"D:\hyperlink.pptx");
List<String> HypLinks = new List<String>();
//Get an Array of TextFrame objects from the first slide
ITextFrame[] textFramesSlideOne = Aspose.Slides.Util.SlideUtil.GetAllTextBoxes(pres.Slides[0]);
//Loop through the Array of TextFrames
for (int i = 0; i < textFramesSlideOne.Length; i++)
//Loop through paragraphs in current TextFrame
foreach (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)
{
HypLinks.Add(port.PortionFormat.AsIHyperlinkContainer.HyperlinkClick.ExternalUrl);
port.PortionFormat.HyperlinkManager.SetExternalHyperlinkClick("customURL.com");
port.Text = "customtext";
}
}
pres.Save(@"D:\hyperlinkURL.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
I hope this will be helpful. Please share if I may help you further in this regard.
Best Regards,
Very cool, that works
Thank you Adnan
Hi Mario,