Quickly looking up documents using Document ID’s in SharePoint – Part 2

In my last post, I discussed some of the issues I had seen with the DocIdRedir.aspx, and I’ve concluded that the main solution is to author a new version of the page, with some enhanced “abilities”.  In my case, I ended up authoring an .ashx page, rather than an .aspx page.  In doing this, I started with two main references:

Kobi’s excellent post on writing an .ashx handler for Doc Id redirection:


The decompiled code from the current DocIdRedir.aspx (as a basis for our new functionality):


In my case, however, I want an entirely different behavior from the “redirect me to the file” behavior.  I’m looking to significantly enhance the data that the handler can return, so that I can get all of the links, metadata, and publishing status of the current document (including returning the link to the latest published version, not the latest version of the file).  As a result, I’ve chosen to return a payload of JSON, with the purpose of letting the calling page / javascript choose the appropriate path based on the returned data.

In this example, my modified DocIdBatchData.ashx has the following features:

  • You can submit a GET request to return the data for a single document OR you can post a collection of Document Id’s to resolve many documents at once.
  • All data is returned in JSON format, allowing javascript to quickly parse and deal with the results.
  • You can request additional metadata to be returned by posting those fields and Document Id’s into the handler.

A sample of the returned data is as follows:

"data": [{
"mData": {
"Title": "SABCS Poster Book"
"docId": "3AWMK2HN32DR-4-3 ",
"versionLabel": "",
"docSiteUrl": "http://myserver:40921",
"docWebUrl": "http://myserver:40921",
"docWebServerRelativeUrl": "/",
"listGuid": "caa79391-faf7-4095-9ed1-486a55dba9bf",
"listName": "Library Objects",
"listItemId": "3",
"listItemFilename": "LOFile2.pdf",
"urlHistory": "_layouts/Versions.aspx?list={caa79391-faf7-4095-9ed1-486a55dba9bf}&ID=3",
"versionLatest": "1.0",
"versionLatestUrl": "Library Objects/LOFile2.pdf",
"versionLatestFolder": "Library Objects",
"versionRequested": "1.0",
"versionRequestedIsPub": true,
"versionRequestedUrlDisplay": "Library Objects/Forms/DispForm.aspx?ID=3&VersionNo=512",
"versionRequestedUrl": "Library Objects/LOFile2.pdf",
"versionRequestedContentType": "0x010100548E9644DF2341A6AE310514AE3913D900130033306EFE434696B5DD9689DC30A4",
"errorStatus": 0,
"errorMessage": null
"errorStatus": 0,
"errorMessage": null

So, the primary value proposition here is that we’ve used the existing DocIdRedir.aspx file resolution, but instead of simply redirecting the user, we are allowing the caller to get some additional data back, and allowing that user / page / javascript / client code to then make a CHOICE about where to go.