How to delete a document, locked by another user ? I'm a super admin.

Environment: SharePoint 2013.

We have a document library. Inside this we have a excel document, when I try to delete the document It says

'The file is currently checked out or locked for editing by another user'

The document is not checked out. The user who locked the file, is not working any more.

How do I delete the document ? BTW, I have the super admin account.

You should be able to release such orphaned locks via impersonating the user first, as described at the end of this post: http://pholpar.wordpress.com/2014/04/03/how-to-use-powershell-to-delete-short-term-locks-from-documents-opened-from-sharepoint/

For example, using PowerShell:

$web = Get-SPWeb http://intranet.contoso.com
$list = $web.Lists["DocLib"] 
$item = $list.GetItemById(2) 
$file = $item.File 
$userId = $file.LockedByUser.ID 
$user = $web.AllUsers.GetByID($userId) 
$impSite= New-Object Microsoft.SharePoint.SPSite($web.Url, $user.UserToken); 
$impWeb = $impSite.OpenWeb(); 
$impList = $impWeb.Lists[$list.Title] 
$impItem = $impList.GetItemById($item.ID) 
$impFile = $impItem.File 
$impFile.ReleaseLock($impFile.LockId)

After the lock has been released, you should be able to delete the document again.

  • Exception calling "ReleaseLock" :"The operation on file [FILE_NAME.xlsx] cannot be completed because the specified lock arguments are not valid. :( – Manivannan Nagarajan Nov 7 '14 at 0:53
  • 1
    What is the check-out status of the document, if you verify that using PowerShell (see full script in the blog post, see fields LockType ... CheckedOutByUser on the screenshot there)? Can you check-out the document via PowerShell, and then undo the check-out as described there? Does the account of the user, who locked the file, exist, or it was deleted already? If it exists, you can reset the password, log in with it, open the file, then close it again. It should delete the lock automatically. In worst case, the lock can be deleted from the AllDocs table from content DB, but it is unsupported. – pholpar Nov 7 '14 at 7:05
  • Awesome, such as sea of answers on this topic and this is the only one that worked for me – Aaron Sep 22 '16 at 21:04

This one works for me. Thanks pholpar

$impitem = $impweb.GetListItem('http://sp2013/XXXXXXXXXXXXXX.xlsx');
$impFile = $impItem.File
$ft = New-Object System.TimeSpan(10000);
$impfile.Lock([Microsoft.SharePoint.SPFile+SPLockType]::Exclusive, "test lock", $ft)
$impfile.UndoCheckOut();
$impfile.Delete();

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:

  1. Send a request to _vti_bin/_vti_aut/author.dll with special headers/body to find the lockid
  2. Send a request to _vti_bin/cellstorage.svc/CellStorageService with a formatted body that includes the lockid
  3. 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")
    })
  }
})

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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