24

I've come up against a problem I've been unable to solve, and based on my 2 days of Binging around, I've yet to find a solution to fix the problem the same with a slew of others. I've got several files in a couple document libraries in a MOSS 2007 site collection that are locked by someone when they no longer have the file checked out. This is preventing others from updating the file or deleting it and replacing it.

SharePoint Manager shows it is checked out by a user and the short term lock on the file is always changing. It will say it is set to expire on 8/8/12 11:00 PM then coming in this morning when the lock should hgave expired, it is extended to 1:05 pm today. This has been going on for several days.

  • I've tried taking ownership of the file - this failes as the item doesn't show as being check out.
  • I've tried to delete it in SPD as some posts reference - doesn't work, and says it's checked out
  • I've tried checking it out and checking it in via content and structure, fails to release the lock.
  • We've had the user check the document out and check it back it, this has not cleared the lock.

Is there something that can be done to clear this file lock? These are critical documents being affected by this. Can Powershell clear those values so the file can be edited?

1
  • I have problems with this sometimes, but to help the situation, usually I require checkout of items before editing on lists/libraries.
    – Mike
    Commented Aug 9, 2012 at 15:31

6 Answers 6

21

For the benefit of future generations, a file lock can be removed via Powershell on an on-premises installation of SharePoint 2010 or later.

How can this happen?

Files can get locked when a client application fails to update the server-side file token that indicates whether a file is currently being edited. (This type of lock is application-specific, and thus different from the explicit Check In/Check Out functionality provided by SharePoint document libraries.) This scenario comes up when computers (or applications) crash unexpectedly, or get disconnected from the network.

With Office products, the file lock is supposed to expire automatically after ten minutes, and this is usually the case. Sometimes a lock seems to persist, which may be the result of browser caching problems or bugs in the way client applications handle the file locks.

How can we fix it?

The Powershell for removing a file lock is as follows:

$web = get-spweb "http://myfarm/mysite/mysubsite"
$list = $web.Lists["My Library"]
$item = $list.Items.GetItemById(123)
$item.File.ReleaseLock($item.File.LockId)
$web.Dispose()

Replace the placeholders with values appropriate to your environment/list/document; use the actual subsite URL in the get-spweb cmdlet, use the library's title to retrieve it from the $web.Lists collection, and use the actual ID of the problem document as the parameter in GetItemById().

This Powershell should be executed from a web front end server on your SharePoint farm. You'll need to load the PS snapin for SharePoint cmdlets such as get-spweb, unless you use the SharePoint Management Shell installed with SharePoint, which starts a Powershell session with the SharePoint snapins already loaded.

Use impersonation if necessary to release the lock

If you run the above Powershell and still run up against an error like this...

Exception calling "ReleaseLock" with "1" argument(s): "The file XXXXXXX is locked for exclusive use by XXXXX"

...you can try using impersonation to release the lock. This is accomplished by using the LockedByUser property of the file to get a reference to the user you need to impersonate, then creating a new SPSite object instance passing in that user's token as a second parameter.

$web = get-spweb "http://myfarm/mysite/mysubsite"
$list = $web.Lists["My Library"]
$item = $list.Items.GetItemById(123)

$userId = $item.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);
$impItem.File.ReleaseLock($impItem.File.LockId)

$impWeb.Dispose()
$impSite.Dispose()
$web.Dispose()

$impSite and $impWeb in the above example are SPSite and SPWeb objects using the impersonated user token.

4
  • 4
    This didn't directly work for me, as I got an error Exception calling "ReleaseLock" with "1" argument(s): "The file XXXXXXX is locked for exclusive use by XXXXX" but that let me to this which did
    – Aaron
    Commented Sep 22, 2016 at 21:06
  • 3
    @Aaron: Nice find! I'll incorporate that impersonation step into this answer and hopefully save the next poor soul from having to dig through so many questions.
    – Thriggle
    Commented Sep 23, 2016 at 14:28
  • How do you find the file ID from SharePoint?
    – TylerH
    Commented Oct 10, 2019 at 21:29
  • @TylerH You can create a personal view that displays the ID column. Alternatively, if you view the properties of the document, you can find the ID in the query string parameters in the URL.
    – Thriggle
    Commented Oct 11, 2019 at 0:30
6

In short, whenever a user has the document open, it locks the file. When that same user has Word lock up or he has it open in the background it will lock that file. The lock will refresh everytime that same user will try to access it again. The user needs to stay out of the file for 10 minutes.

Link: http://support.microsoft.com/kb/899709

  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.

Source: http://www.techtimepiece.com/2012/04/sharepoint-error-file-is-locked-for.html

When things get tough, my resolution usually is sometimes an IISReset.

6

This has happened to me several times in SharePoint Online (2013). I will describe below my scenario and my solution which worked instantly.

Scenario:

  • User has a SharePoint file open in edit mode.
  • User disconnects from the network or restarts computer without properly closing the file
  • When user tries to edit the same file after rebooting they receive a message stating the file is checked out to themselves

Solution:

  • In Internet Explorer go to "Internet Options"
  • Delete browsing history
  • Problem solved
4
  • 1
    I just wanted to weigh in that Michael's solution (March 2) worked for us. We had a file that was locked for editing, and going to the person's PC and clearing her IE cache solved it! Thank you very much. -Charlie Kopp -Seattle
    – user48537
    Commented Nov 5, 2015 at 19:42
  • You're very welcome!
    – Michael
    Commented Nov 23, 2015 at 15:26
  • 2
    Does it matter which browser the user generally accesses the SharePoint site with? For example, do you still clear the IE cache when using Chrome? Commented Aug 31, 2016 at 22:47
  • Does this apply if user is using traditional Word & Excel to open documents?
    – JohnC
    Commented Dec 22, 2021 at 14:01
3

Office has to be continuing to extend that short term lock. You may check if this is the issue: http://paulliebrand.com/2008/01/04/document-is-locked-for-editing/ or check this http://paulliebrand.com/2010/04/12/document-is-locked-for-editing-part-2/

So as listed in part two, you can monitor on the workstation to see what may be keeping that short term lock open.

Let me know if this doesn't help. Then you have to get into much more complicated methods to clear the lock.

1
  • these 2 links are returning a 401 error
    – JohnC
    Commented Dec 22, 2021 at 14:03
1

We never resolved this at the time of me leaving the company. The locks persisted to extend and presumably were resolved when the farm was upgraded to 2010.

1
  • 1
    damn, that's one way to leave a legacy
    – NBN-Alex
    Commented Aug 5, 2020 at 18:23
-1

Problem: PowerPoint Presentation was locked for editing purposes to another user. Yet they could not edit, delete, or check-in the document.

Solution: Proceed to document library and enabled check-in and check-out function.

Problem: PowerPoint Presentation was locked for editing proposed to me, but I could not edit, delete, or check-in the document.

Solution: Proceed to the library where the document was being held. Checked out a different document in the same folder. Then, checked-out the presentation we were having issues with. The system recognized both as being checked out to me. Then, I checked them both back in. Problem solved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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