If you're looking for a client-side solution for Sharepoint 2013 On-Promise that can be executed in JavaScript, I found some good stuff on this blog that I have updated on mine.
To unblock the short term lock for a file:
- Send a request to
_vti_bin/_vti_aut/author.dll
with special headers/body to find the lockid
- Send a request to
_vti_bin/cellstorage.svc/CellStorageService
with a formatted body that includes the lockid
- The file is unlocked
Tested for Sharepoint 2013 On-Promise only. I don’t know if this solution works for Sharepoint Online or other version.
Please note that I use $SP().ajax()
from SharepointPlus, but it’s equivalent to the $.ajax()
from jQuery.
// full path to the document
var docUrl = "https://website.com/website/Doc_Library/Test.docx";
// start by querying author.dll to find the lockid and the user who locked it
$SP().ajax({
url: 'https://website.com/website/_vti_bin/_vti_aut/author.dll',
headers:{
"Content-Type": "application/x-www-form-urlencoded",
"MIME-Version": "1.0",
"Accept": "auth/sicily",
"X-Vermeer-Content-Type": "application/x-www-form-urlencoded"
},
body: 'method=getDocsMetaInfo%3a14%2e0%2e0%2e6009&url%5flist=%5b' + encodeURIComponent(docUrl) + '%5d&listHiddenDocs=false&listLinkInfo=false',
}).then(function(source) {
// go thru the source page returned to find the lockid and current user
var nextLine = false;
var ret = { "lockid":"", "user":"" };
source.split("\n").forEach(function(line) {
if (line.indexOf("vti_sourcecontrollockid") !== -1) nextLine="lockid"; // vti_sourcecontrollockid -> the lockid to use later
else if (line.indexOf("vti_sourcecontrolcheckedoutby") !== -1) nextLine="user"; // vti_sourcecontrolcheckedoutby -> username of the user who locked it
else if (nextLine !== false) {
ret[nextLine] = line.slice(7).replace(/&#([0-9]|[1-9][0-9]|[[01][0-9][0-9]|2[0-4][0-9]|25[0-5]);/g, function (str, match) { return String.fromCharCode(match); });
nextLine = false;
}
});
if (!ret.lockid) { alert("Not Locked") }
else {
// compose a request based on what Microsoft Office sends to the Sharepoint server
// found using Fiddler
var releaseLockReq = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><RequestVersion Version="2" MinorVersion="2" xmlns="'+docUrl+'" UseResourceID="true" UserAgent="{1984108C-4B93-4EEB-B320-919432D6E593}" UserAgentClient="msword" UserAgentPlatform="win" Build="16.0.8201.2102" MetaData="1031" RequestToken="1"><SubRequest Type="ExclusiveLock" SubRequestToken="1"><SubRequestData ExclusiveLockRequestType="ReleaseLock" ExclusiveLockID="'+ret.lockid+'"/></SubRequest></Request></RequestCollection></s:Body></s:Envelope>';
// we send it to the webservice cellstorage.svc
$SP().ajax({
url:'https://website.com/website/_vti_bin/cellstorage.svc/CellStorageService',
body:releaseLockReq,
headers:{
'Content-Type':'text/xml; charset=UTF-8',
'SOAPAction': "http://schemas.microsoft.com/sharepoint/soap/ICellStorages/ExecuteCellStorageRequest"
}
})
.then(function(res) {
if (res.indexOf('ErrorCode="Success"') !== -1) alert("Success") // the file has been unlocked
else alert("Failed")
})
}
})