Skip Ribbon Commands
Skip to main content

Erin Glenn's Blog


Erin Glenn's Blog > Posts > "File is locked for editing by..."
May 22
"File is locked for editing by..."

I had a user that had made edits to a file and checked it back in. Other users were trying to open the file and make edits, but were receiving the error on edit that the file was locked for editing by the original user.

Ultimately, I had to run some Powershell to unlock the file manually.  I found these commands on this blog​.

To see the details of the file lock/confirm the file is locked:

$web = Get-SPWeb 
$list = $web.Lists["DocLib"] 
$item = $list.GetItemById(2) 
​$file = $item.File 

To impersonate the user who has the lock and unlock the file:

$web = Get-SPWeb 
$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 


There are no comments for this post.