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/

Document Library throwing System.Runtime.InteropServices.COMException error when trying to open files.

Recently I came across an Image Library on a SharePoint 2010 farm where the thumbnails were visible but opening the images threw a correlation ID. The error message behind the ID was a System.Runtime.InteropServices.COMException which is an ACL related issue. The library inherited permissions from its parent so to solve this issue I broke inheritance and re-established inheritance again. When I re-established inheritance the system refreshed the ACL from the parent and fixed the issue.

About the author

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

Month List

Page List