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."

https://msdn.microsoft.com/en-us/library/system.uri.absolutepath%28v=vs.110%29.aspx?f=255&mspperror=-2147217396


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -