Click here to Skip to main content
15,920,468 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:

I am working on an assignment in which I have to fetch list of hyperlinks existing in a docx file. The file may contain links in headers/footers as well.
The approach I am using is through OpenXML. I have been able to detect Hyperlinks that are existing in the body of the docx file using the approach below :
IEnumerable<HyperlinkRelationship> hyperlinks = from r in wordDocx.MainDocumentPart.HyperlinkRelationships where ((r.RelationshipType == "")) select r;
foreach (HyperlinkRelationship hr in hyperlinks)
 if (isValidURL(hr.Uri.ToString()))

Any suggestions on how to iterate through the header/footer document parts and check for existence of Hyperlinks?


It has code in C# sections. Check if it helps you.[^]
Share this answer
Karunish 18-Apr-11 8:26am    
Have tried that mate. Problem is I am not able to form Hyperlink relationship for the Header/footer part reference.
We need to iterate withing HeaderFooterReference class to create HyperlinkRelationship and then use LINQ Query to find the result. Here is how I resolved this problem.
protected ListBox GetHeaderFooterHyperLinks(WordprocessingDocument wordDocx)
     string headerFooterRelationshipID;
     foreach (HeaderFooterReferenceType hdrFtr in wordDocx.MainDocumentPart.Document.Descendants<HeaderFooterReferenceType>())
         headerFooterRelationshipID = hdrFtr.Id.Value;
         IEnumerable<HyperlinkRelationship> hdrFtrLinks = from hdrFooter in wordDocx.MainDocumentPart.GetPartById(headerFooterRelationshipID).HyperlinkRelationships where (hdrFooter.RelationshipType == "") select hdrFooter;
    foreach(HyperlinkRelationship hf in hdrFtrLinks)
  return lstBox;
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900