Reputation: 6483
I`m looking for a way to read a links between slides in single PowerPoint presentation. I need to open a PowerPoint file and retrieve all links slides have to each other.
Right now I`m using Aspose but it appears they do not have anything to read links between slides.
I've read some more about the PowerPoint 2007/2010 file format and found out that it`s just a zip archive. After renaming it you can see all the xml data inside it. Does anybody know which one of the many xml files inside it contains information what slide is linked and to what slide?
I need to do it in C# or VB.NET.
Upvotes: 4
Views: 1904
Reputation: 1607
To accomplish this in C#, here is a good method to find the linked slide:
private int GetSlideIndexFromHyperlink(Hyperlink hyperlink)
{
var subAddrParts = hyperlink.SubAddress.Split(',');
return int.Parse(subAddrParts[1]);
}
Note that the Hyperlink is found within the desired ActionSettings for the Shape you care about (in my case it was shape.ActionSettings[PpMouseActivation.ppMouseClick]
.
The sub-address for linking in PowerPoint is formatted like SlideId,SlideIndex,SlideTitle
. It should be rather simple to obtain the other parts(if desired) with this method via some small tweaks.
Upvotes: 0
Reputation: 29155
There's no need to go to OpenXML here if you don't have to - this can be done with the Object Model. Here's how it is done in VBA, which can easily be ported to C# or VB.NET.
Sub PrintInteralLinks()
Dim ap As Presentation
Set ap = ActivePresentation
Dim hs As Hyperlinks
Dim h As Hyperlink
Dim sl As Slide
Dim linkedToSlide As String
Dim slideTitle As Integer
For Each sl In ap.Slides
Set hs = sl.Hyperlinks
For Each h In hs
slideTitle = InStrRev(h.SubAddress, ",")
If slideTitle > 0 Then
linkedToSlide = Mid(h.SubAddress, slideTitle + 1)
Debug.Print sl.Name & " links to " & linkedToSlide
End If
Next
Next
End Sub
The slideTitle = InStrRev(h.SubAddress, ",")
isn't fool-proof though. The pattern for internal links is #,#,Slide Title
, so you may have to make this better with like some RegEx.
Upvotes: 2