Monday, December 1, 2014

SharePoint 2010: File locked for editing by xxx

In SharePoint 2010 it is very frequent to see users complaining of encountering this particular error when they try to edit a file in Office 2010 client.

It is because the SharePoint server will attempt to check every 10 minutes whether the user performing the edit still has the file handle open for editing.

According to the KB - waiting 10 minutes usually resolves the problem - http://support.microsoft.com/kb/899709

Sometimes, even though the user has checked in.closed the file after making his changes, other users still could not access the file for editing.

As stated in this article - http://www.techtimepiece.com/2012/04/sharepoint-error-file-is-locked-for.html
This could be due to the following reasons:
  1. System crashes while the file is still open.
  2. File has been closed unexpectedly.
  3. Check in was not successful.
  4. Network connection is lost while file is still open.
And this is the suggested solution:
  1. Check whether the file has been properly checked in or not. If not, refresh the page and try to check in the file again.
  2. Delete the local copy of the file present in the cache folder of the concerned user account (access to user’s PC required).
  3. Close all the instances of file type opened in the system. E.g. if the file type is excel, then close all the excel files currently opened.
  4. Also kill the file type service (excel in this case) using the task manager.
But if all fails, there is trusty ol PowerShell to the rescue!
Run this script in your web application server:

$gc = Start-SPAssignment
$web = ($gc | Get-SPWeb )
$list = $web.Lists[""]
$item = $list.GetItemById()
$file = $item.File
$userId = $file.LockedByUser.ID
if (![string]::IsNullOrEmpty($userId))
{
 $user = $web.AllUsers.GetByID($userId)
 Write-Host "File is being locked by... "
 $user
 Write-Host "Attemping to release lock... "
 $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)
 Write-Host "Lock successfully released... "
 $impSite.Dispose()
} else {
 "No lock detected for $file"
}
Stop-SPAssignment $gc

1 comment:

Karen said...

Does this script allow you to define the one document/user id that you want to unlock, or is it releasing all current file locks on the system?

Related Posts Plugin for WordPress, Blogger...