SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Originally titled "Get document-version independent URL"

I'm using the Versions.asmx SharePoint webservice, where I get the following output message:

<results xmlns="">
 <list id="{E0A3AEC1-A35E-47D6-8595-C89E75ECAA06}" />
 <versioning enabled="1" />
 <settings url="http://server/Site/_layouts/LstSetng.aspx?List={E0A3AEC1-A35E-47D6-8595-C89E75ECAA06}" />
 <result version="@2.0" url="http://server/Site/DocLib/Folder/doc.xlsx" created="10/8/2012 1:14 PM" createdRaw="2012-10-08T11:14:46Z" createdBy="SHAREPOINT\system" createdByName="System Account" size="109694" comments="" />
 <result version="1.0" url="http://server/Site/_vti_history/512/DocLib/Folder/doc.xlsx" created="10/8/2012 1:12 PM" createdRaw="2012-10-08T11:12:23Z" createdBy="SHAREPOINT\system" createdByName="System Account" size="110111" comments="" />

The problem here is that the latest version (marked with the @ symbol) always returns the original URL, but what I really want, is an URL like the other versions (like /_vti_history/<M*512+m>/DocLib/Folder/doc.xlsx) that will serve as a permanent link to the version that is current now for the times when it gets superseded by later versions. Anyone an idea how to get this? (if possible)

share|improve this question

Direct link to a certain version of a document :

Update: This is a link to a solution by Hans Worst, who suggests to rely on javascipt to asynchronously check for the existence of the Version's existence.

The core function goes below:

function check_file(path_of_file) 
{"HEAD", path_of_file);
  http_check.onreadystatechange = handleHttpResponse_check;

  function handleHttpResponse_check()
    if(http_check.readyState == 4){
        if (http_check.status == 200) {
        }else if (http_check.status >= 400) {
        }else {

He initially checked for http_check.status == 404, but as the server might return 400 instead, hence the slight change to greater than or equal to 400.

Also, Hans uses a calculated field to display the link to a major version:

Formula: ="<a href='javascript:' onclick="&CHAR(34)&"check_file('/site/_vti_history/"&VALUE(LEFT(DocVersion;1))*512&"/Documents/Specifications.pdf')"&CHAR(34)&">Standard specifications</a>"

share|improve this answer
Added some details from the blog – Alexey Krasheninnikov Nov 13 '14 at 17:14
up vote 1 down vote accepted

Since SharePoint doesn't accept the URL to the current version via /_vti_history/ as valid (returning 400 or 404 as HTTP status), we must substitute these standard URLs with links to a custom ASP.NET page which in turn redirects to the correct URL of the version, whether it's current or historical. We pass the versionlabel in the querystring of this new page.

Update: Stefan Stanev has a sample of such page:

The core part of the page in his implementation is as follows:

    string fileRef = this.Request.QueryString["FileRef"];
    int version = int.Parse(this.Request.QueryString["Version"]);

    SPWeb web = SPContext.Current.Web;
    SPFile file = web.GetFile(fileRef);
    SPListItem item = file.Item;

    string redirUrl = null;
    if ((int)item["_UIVersion"] == version) redirUrl = web.Url.TrimEnd('/') + "/" + file.Url;
        foreach (SPListItemVersion v in item.Versions)
            if ((int)v["_UIVersion"] == version)
                redirUrl = web.Url.TrimEnd('/') + "/_vti_history/" + version + "/" + file.Url;
    if (redirUrl != null)

Stefan also defines a custom field to display a link for each version

share|improve this answer
Added info about Stefan Stanev's solution – Alexey Krasheninnikov Nov 13 '14 at 16:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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