Getting the anchor of an external link


#1

We deal with a code sample which retrieves the url of external links for a given presentation:

Private Function extractUrlsFromPst(ByVal pstPath As String) As String()
    Dim pst As Slides.Presentation = New Slides.Presentation(pstPath)
    Dim urls As List(Of String) = New List(Of String)
    For Each hlc As Slides.IHyperlinkContainer In pst.HyperlinkQueries.GetAnyHyperlinks
        Dim url As String = hlc.HyperlinkClick.ExternalUrl
        If url Is Nothing Then Continue For
            urls.Add(url)
        Next
        Return urls.OrderBy(Function(obj) obj).ToArray
End Function

If one url ends with a named anchor (for example #top), it won’t be kept in the ExternalUrl class member, and I didn’t find it in another member. Is there a way to retrieve it?

You’ll find attached a sample file containing a link with a named anchor in the second slide.

Regards,
Monir

links.zip (25.0 KB)


#2

@monir.aittahar,

I have worked with the sample code and presentation file shared and have been able to observe the issue specified. An issue with ID SLIDESNET-41089 has been created in our issue tracking system to investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.


#3

@mudassir.fayyaz,

Thank you for your answer. Also I noted that anchor name is appended to the url for presentations and workbooks, but not for documents: for them, the anchor name is in FieldHyperlink.SubAddress.

Why this difference?

Regards,
Monir


#4

@monir.aittahar,

Do you mean that for Word documents (using Aspose.Words) there is any issue incurred on your end?


#5

@mudassir.fayyaz,

No, It was just a question: why the anchor (#something) is stored in a separate class member (SubAddress) in the Words API and neither for Slides or Cells, for which it’s kept appended to the URLs?


#6

@monir.aittahar,

Please see this sample Word document:
in.zip (9.7 KB)

And try running the following code:

Document doc = new Document("E:\\Temp\\in.docx");

foreach(Field field in doc.Range.Fields)
{
    if (field.Type == FieldType.FieldHyperlink)
    {
        FieldHyperlink link = (FieldHyperlink) field;
        Console.WriteLine(link.SubAddress);
    }
} 

In this case when the hyperlink points to a location inside document, the value will be stored in SubAddress property. Hope, this helps.


#7

@awais.hafeez,

SubAdress contains also anchor name of an external Url (for example, it will contain top for the url http://example.com#top).

I was asking why Words.Api stores the anchor separately since Calc and Slides let it appended to the url (neither Cells.HyperLink nor Slides.IHyperLinkContainer.HyperlinkClick have a SubAddress member class). I wanted to understand the philosophy behind the implementation. :slight_smile:


#8

@monir.aittahar,

Generally, the SubAddress property just returns the \l switch value. We need to check the field’s code if it contains \l “top”. Please ZIP and upload your sample Word document here for testing. We will then investigate the issue on our end and provide you more information.


#9

@awais.hafeez,

Thanks. The only issue we had was the one labelled as SLIDESNET-41089 in the post of @mudassir.fayyaz (losing the anchor of an external link). I already sent a sample relateted to this issue.

Regards,
Monir


#10

@monir.aittahar,

We will share the good news with you as soon as the issue will be fixed.


#11

@mudassir.fayyaz,

Thanks, I’ll stay tuned. :slight_smile:


#12

The issues you have found earlier (filed as SLIDESNET-41089) have been fixed in this update.


#13

Dear all,

Thanks for the good news.

Regards.


#14

@monir.aittahar,

You are very welcome.


#15

Dear all,

Thank you very much, I’ve just tested the fix and it’s working.

Regards.


#16

@monir.aittahar,

Thank you for sharing valuable feedback.