Dormamu
Dormamu

Reputation: 30

How to insert a link as a shape to a slide from another slide inside same presentation using open xml?

I have a scenario where I want the user to be taken to a different slide in the same presentation when they click on a shape containing texts "take me to slide 2" from slide 1 or slide 3 using open xml.

    using (PresentationDocument presentationDocument = PresentationDocument.Open(presentationFile, true))
{
PresentationDocument presentationPart = presentationDocument.PresentationPart;
SlideIdList slideIdList = presentationPart.Presentation.SlideIdList;
var slideParts = presentationDocument.PresentationPart.SlideParts;

SlideId firstSlideId = (SlideId)slideIdList.ChildElements[0];

foreach(var slidePart in slideParts)
{
    var hyperlinkOnClicks = slidePart.Slide.Descendants<DocumentFormat.OpenXml.Drawing.HyperlinkOnClick>();
    string rId = "rId9999";
    var newHyperLinkRelationship = slidePart.AddHyperlinkRelationship(new Uri("#" + firstSlideId.RelationshipId, Urikind.Relative), true, rId);
    foreach(var hyperlinkOnClick in hyperlinkOnClicks)
    {
        hyperlinkOnClick.Id = newHyperLinkRelationship.Id;
    }

    presentation.Presentation.Save();
    presentationDocument.Save();
}
}

enter image description here

Upvotes: 0

Views: 50

Answers (0)

Related Questions