A file is exclusively locked by a desktop application in a SharePoint document library

Have you ever had an issue where a user opened a file in an Office application and went on holiday? Since the file was locked on the client side nobody could check it out or edit it. Well one of my users had this issue. SharePoint calls it ShortTerm lock. You can check it using the below PowerShell code:

$l = $w.Lists["Documents"]
$i = $l.GetItemById(1)
Write-Host $i.File.CheckOutStatus
 

If the status is ShortTerm you can lift the lock with

[string]$url = "Site URL"
[string]$list = "Library name"
[string]$item = "Document ID"

$w = get-spweb $url
$l = $w.lists[$list]
$i = $l.GetItemById($item)
$s = New-Object Microsoft.SharePoint.SPSite($w.site.id, $i.File.LockedByUser.UserToken)
$w = $s.OpenWeb($w.id)
$l = $w.lists[$list]
$i = $l.GetItemById($item)
$i.File.ReleaseLock($i.File.LockId) 

Thanks to http://sharepointobservations.wordpress.com/2013/09/10/remove-sharepoint-client-side-file-lock/

About the author

Hi! I'm Marcell Mikolcsó, SharePoint and Enterprise Administrator, System Architect.

Month List

Page List