Hi Mandar,
Thanks for your patience. It is to update you that we have closed the issue (WORDSNET-14097) with “Won’t Fix” resolution.
Hyperlinks which refer to bookmark internal are:
Bookmark : refer to existing bookmark
Heading : refer to auto created hidden bookmark at the beginning of heading paragraph.
But the HYPERLINK field can be created manually and any bookmarks can be used. Moreover, MS Word supports HYPERLINK field that refers heading by it text. Please use following code example to determine either the hyperlink points to bookmark or heading. Hope this helps you.
Document document = new Document(MyDir + "in.docx");
BookmarkCollection bookmarks = document.Range.Bookmarks;
List<Paragraph> headings = document.GetChildNodes(NodeType.Paragraph, true)
.Cast<Paragraph>().Where(p => p.ParagraphFormat.IsHeading).ToList();
foreach (FieldHyperlink field in document.Range.Fields.OfType<FieldHyperlink>())
{
Console.Write(field.GetFieldCode() + ": ");
if (string.IsNullOrEmpty(field.SubAddress))
{
Console.WriteLine("does not point to bookmark or heading");
continue;
}
Bookmark bookmark = bookmarks[field.SubAddress];
if (bookmark == null)
{
if (headings.Any(p => p.GetText().TrimEnd(ControlChar.ParagraphBreakChar) == field.SubAddress))
{
Console.WriteLine("points to heading by it text");
}
else
{
Console.WriteLine("does not point to anything");
}
}
else
{
if (bookmark.BookmarkStart.NextSibling == bookmark.BookmarkEnd &&
bookmark.BookmarkStart.ParentNode.NodeType == NodeType.Paragraph &&
((Paragraph)bookmark.BookmarkStart.ParentNode).ParagraphFormat.IsHeading)
{
Console.WriteLine("points to heading by bookmark");
}
else
{
Console.WriteLine("points to bookmark");
}
}
}