c# - How to get absolute URI of hyperlink in MS word using OpenXML SDK? -
a ms word file contains link local files (ms word, excel, visio ...), used openxml absolute uri of linking local files. filename.
could give me advice?
using (wordprocessingdocument document = wordprocessingdocument.open(docxfile, true)) { body body = document.maindocumentpart.document.body; //----------------------------------------------- documentformat.openxml.wordprocessing.hyperlink hlink = body.descendants<documentformat.openxml.wordprocessing.hyperlink>().firstordefault(); if (hlink != null) { // hyperlink's relation id (where path stores) string relationid = hlink.id; if (relationid != string.empty) { // current relation hyperlinkrelationship hr = document.maindocumentpart.hyperlinkrelationships.where(a => a.id == relationid).firstordefault(); if (hr != null) { string path = hr.uri.absolutepath; //exception } } } }
just use hr.uri.tostring() method path
according msdn: "the absolutepath property contains path information server uses resolve requests information."
Comments
Post a Comment