Looking for the simplest possible solution, but needs to be JavaScript/jQuery if at all possible.

I have an XML document that I am transforming using XSLT to render an HTML page. This XML document contains a link to another XML document. The only information in the source XML about the linked document is an absolute URL.

Using only the URL of the document, how can I retrieve the document's ID?


1 Answer 1


Unfortunately the absolute URL isn't the best, but it's something :)

You'll better need to have the site relative URL for the file, which you can pass then to GetFileByServerRelativeUrl available in Web object, using the correct Web where the file is. This method is available also in CSOM and REST API, so you can build and issue the REST query directly from your JS.

See Working with files by using REST

If your documents are coming from different libraries, sites or site collection it can be challenging to 'compose' the relative URL properly, but if they're all residing in the same Web shouldn't be too hard

  • Thanks! I can actually predict with 100% certainty that the documents will be coming from the same library. Does that simplify things? May 20, 2015 at 19:03
  • yes, if you use the CSOM approach (clientContext) then you probably can just use SP.ClientContext.get_current().get_web(), without having to open different webs for different documents. In case you go for the REST approach you can just assume the starting URL to be: http://<yoursite>/_api/web/getFileByServerRelativeUrl('<doc relative url>') just replacing last parameter for different files May 20, 2015 at 20:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.