I am using code from http://www.aspose.com/docs/display/wordsnet/How+to++Replace+or+Modify+Hyperlinks to process hyperlinks in Word document.
In attached test document (in BIN/Debug folder, Hyperlink.doc) you can find few links with TextToDisplay "G:\BBD_GES\Handbuch\1
Betriebliches\Amtsgeheimnis\Bestätigung Geheimhaltungspflicht.doc" but hyperlink behind this TextToDisplay is "\\nas2.winlan.net\g_6vb$\BBD_GES\Handbuch\1 Betriebliches\Amtsgeheimnis\Bestätigung Geheimhaltungspflicht.doc"
It looks like that code that you provided (where I am thankful) does not work properly as it returns as a hyperlink only TextToDisplay but cannot really find hyperlink.
for (Node node = fieldStart; node != null && node.NodeType != NodeType.FieldSeparator && node.NodeType != NodeType.FieldEnd; node = node.NextPreOrder(node.Document)) { // Use text only of Run nodes to avoid duplication. if (node.NodeType == NodeType.Run) builder.Append(node.GetText()); } return builder.ToString(); }
public void ReadHyperlinks() { // Specify your document name here. Console.WriteLine("1." + DateTime.Now.ToString()); Aspose.Words.Document doc = new Aspose.Words.Document("hyperlink.doc"); Console.WriteLine("2." + DateTime.Now.ToString()); // Hyperlinks in a Word documents are fields, select all field start nodes so we can find the hyperlinks. NodeList fieldStarts = doc.SelectNodes("//FieldStart");
foreach (FieldStart fieldStart in fieldStarts) {
Console.WriteLine(GetFieldCode(fieldStart));
//if (fieldStart.FieldType.Equals(FieldType.FieldHyperlink)) //{ // // The field is a hyperlink field, use the "facade" class to help to deal with the field. // Hyperlink hyperlink = new Hyperlink(fieldStart);
// // Some hyperlinks can be local (links to bookmarks inside the document), ignore these. // if (hyperlink.IsLocal) // continue;
//// The Hyperlink class allows to set the target URL and the display name //// of the link easily by setting the properties. //Console.WriteLine("1. Hyperlink Target: " + hyperlink.Target); //Console.WriteLine("2. Hyperlink Name: " + hyperlink.Name); //} } Console.WriteLine("3." + DateTime.Now.ToString()); }
Thanks for your inquiry. We have tested the scenario and have noticed that Hyperlink address is not imported into Aspose.Words.Document. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-13240. You will be notified via this forum thread once this issue is resolved.
We regret to share with you that the implementation of this issue has been postponed (no estimate is available at the moment). We will inform you via this thread as soon as this issue is resolved.