So SharePoint thinks my file is checked out!

Recently I had an issue with a word document that was marked as checked out in SharePoint 2013 but there was no checked out icon nor I could check in the file. At first I taught I could use the Discard Check out button in the Office ribbon in the FILES section. The button was greyed out and i wasn’t able to edit the file. Every time i would press Check Out, there will be an error popping up saying that the file was locked for editing and checked out for another user. I contacted the user and asked him to login inside and check if he was able to Check In the file. Unfortunately he was also unable to Check In the file. He also got the same error saying that the file was Checked Out by him.

So what to do?

As always there is a solution but we have to use powershell and open the webpage using powershell in the context of the user and use the ReleaseLock cmdlet.

First we have to get the UserID for the user that holds the file:

$myWeb = Get-SPWeb http://thenameofyoursite

$myFile = $myWeb.GetFile(“the path to your document”)

$myUserID = $myFile.LockedByUser.ID

$myUser = $myWeb.AllUsers.GetByID($myUserID)

 

Now that we have the user ID, we can open the site in the context of this user and do the ReleaseLock:

$impSite = New-Object Microsoft.SharePoint.SPSite($myWeb.Url, $myUser.UserToken)

$impWeb = $impSite.OpenWeb()

$fileURL = “the path to your document”

$impFile = $impWeb.GetFile($fileURL)

$impFile.ReleaseLock($myFile.LockId)

 

That is it. The file should be released and it can be accessed by other users.

 

This entry was posted in SharePoint 2010, SharePoint 2013, SharePoint 2016 and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *