Sorry, something went wrong – The file FILENAME is locked for exclusive use by USER

Problem:  End-Users receives error when trying to edit a file. “Sorry, something went wrong – The file FILE-URL is locked for exclusive use by USER-NAME”

Sorry, something went wrong - The file FILENAME is locked for exclusive use by USER
Open Document The File FILENAME is locked for exclusive use by USER

Root Cause:
When users edit the document in client applications such as Microsoft Office, SharePoint places a lock and renews it every 10 minutes to prevent other users from modifying it. This lock is released automatically when the client application is closed, or after 10 minutes.

Solution:

But in some scenarios, lock retains due to reasons like: Client application crash, Network connectivity issues, etc.  So, the simplest solution would be to wait for 10 minutes for the lock to expire. But if you want the lock to be released immediately, You can unlock it programmatically!

There is no UI to unlock the locked files – as we do have for Check-in Checked-out files. So, Here is my solution to unlock the locked files using PowerShell.

 Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

#Variables for Web and File URLs
$WebURL ="http://intranet.crescent.com/support/"
$FileURL ="http://intranet.crescent.com/support/T1Support/Reports/ServiceTickets.xlsx" 

#Get Web and File Objects
$web = Get-SPWeb $WebURL
$File = $web.GetFile($FileURL)

#Check if File is Checked-out
if ($File.CheckOutType -ne "None")
 {
    Write-host "File is Checked Out to user: " $File.CheckedOutByUser.LoginName
    Write-host "Checked Out Type: " $File.CheckOutType
    Write-host "Checked Out On: "  $File.CheckedOutDate

    #To Release from Checkout, Ask the checked out user to Checkin
    #$File.Checkin("Checked in by Administrator")
    #Write-host "File has been Checked-In"
 }
 
 #Check if File is locked
 if ($File.LockId -ne $null)
 {
     Write-host "File is Loked out by:" $File.LockedByUser.LoginName
     Write-host "File Lock Type: "$file.LockType
     Write-host "File Locked On: "$file.LockedDate
     Write-host "File Lock Expires on: "$file.LockExpires

     #To Release the lock, use:
     #$File.ReleaseLock($File.LockId)
     #Write-host "Released the lock!" 
 }

Don’t forget to uncomment the lines 32-33 if you find your files are locked out.

Salaudeen Rajack

Information Technology Professional with Two decades of SharePoint Experience.

14 thoughts on “Sorry, something went wrong – The file FILENAME is locked for exclusive use by USER

  • June 2, 2020 at 2:14 PM

    how it is possible to unlock files regularly ? Does Office Online also lock file ? I have observed the same.

    Reply
  • April 1, 2020 at 6:18 PM

    Looks like this script has impersonation built in, for unlocking the file: https://gallery.technet.microsoft.com/office/locked-for-exclusive-use-28b8bbf3

    Reply
  • October 11, 2019 at 1:54 PM

    Hi,

    Is there any script for SharePoint online as well?

    Thanks,
    SV

    Reply
  • May 29, 2018 at 2:26 PM

    Getting same issue ,error message”Exception calling ‘ReleaseLock’ with ‘1’ argument(s)”

    Reply
  • March 21, 2018 at 7:45 PM

    Thanks for the script. Can impersonation be added to this?
    I now get the following error message”Exception calling ‘ReleaseLock’ with ‘1’ argument(s)”

    Reply
    • March 22, 2018 at 6:05 AM

      Run the script from Farm Admin account or any account which has “Full Control” Web application user policy granted.

      Reply
  • March 21, 2018 at 7:43 PM

    I now get the following error: Exception calling “ReleaseLock” with “1” argument(s).”

    Can I add impersonation to this script?

    Reply
  • February 22, 2018 at 7:28 PM

    Do you run this script on the server? Where is the setting for the 10 minute lockout. Our network does not have a 10 minute lockout. Is this done manually?

    Reply
  • September 25, 2017 at 12:35 PM

    Does it work for SharePoint online?

    Reply
  • March 14, 2017 at 2:38 PM

    Excellent! thanks dude!

    Reply
  • March 15, 2016 at 5:40 PM

    Where/how do I input this code?

    Reply
    • November 1, 2016 at 12:37 PM

      Use either PowerShell ISE or Save this script as a .ps1 file and run from PowerShell console. Don’t forget to change WebURL and FileURL variables.

      Reply
  • November 20, 2015 at 7:58 PM

    Thanks man you are a life saver!!!

    Reply

Leave a Reply