none
SharePoint Document locked by another user

    Question

  • I am working with SharePoint online. After a user has finished editing and closed the document, SharePoint still locks it down for that user making us not able to interact with the document as we want. I have checked online and i was able to find a solution that suits my need but only works for on-prem sharepoint.

    param (
        [string]$url,
        [string]$list,
        [string]$item
    )
    $w = get-spweb $url
    $l = $w.lists[$list]
    $i = $l.GetItemById($item)
    $s = New-Object Microsoft.SharePoint.SPSite($w.site.id, $i.File.LockedByUser.UserToken)
    $w = $s.OpenWeb($w.id)
    $l = $w.lists[$list]
    $i = $l.GetItemById($item)
    $i.File.ReleaseLock($i.File.LockId)

    when I modified this for cloud to

    param ( [string]$url, [string]$list, [string]$item )

    Connect-SPOService -Url https://mysiteurl.com - credential myusername $w = get-sposite -identity $url $l = $w.lists[$list] $i = $l.GetItemById($item) $s = New-Object Microsoft.SharePoint.SPSite($w.site.id, $i.File.LockedByUser.UserToken) $w = $s.OpenWeb($w.id) $l = $w.lists[$list] $i = $l.GetItemById($item) $i.File.ReleaseLock($i.File.LockId)

     got an error "cannot index into a null array" at $l = $w.lists[$list] 

    Am not good with writing powershell script. What am I doing wrong please?

    Thursday, August 4, 2016 7:49 AM

Answers

  • Hi Olabiwonnu,

    There is no such method supported in client object model or JavaScript object model to release the file lock, so we cannot achieve the same in SharePoint online programmatically.

    For now, you may need to try the manually way.

    Best Regards,

    Victoria 


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    • Marked as answer by Olabiwonnu Monday, October 9, 2017 8:20 AM
    Saturday, August 6, 2016 1:56 AM
    Moderator

All replies

  • Hi Olabiwonnu,

    The PowerShell script you provided can only be used in SharePoint on-premise and there is no such PowerShell supported to release the file lock for SharePoint online.

    So for SharePoint online, please check if the file has been checked out now. If yes, please check it in first.

    And also check if the user who edited the file has closed the file in his computer.

    If above does not help, please check the link below for troubleshooting this issue:

    https://www.puryear-it.com/troubleshooting-locked-documents-sharepoint-office-365

    Best Regards,

    Victoria 


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Friday, August 5, 2016 5:43 AM
    Moderator
  • Hi Victoria,

    Thanks for the feedback.

    Just need a way to programatically release lock

    • Edited by Olabiwonnu Friday, August 5, 2016 11:04 AM
    Friday, August 5, 2016 11:02 AM
  • Hi Olabiwonnu,

    There is no such method supported in client object model or JavaScript object model to release the file lock, so we cannot achieve the same in SharePoint online programmatically.

    For now, you may need to try the manually way.

    Best Regards,

    Victoria 


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    • Marked as answer by Olabiwonnu Monday, October 9, 2017 8:20 AM
    Saturday, August 6, 2016 1:56 AM
    Moderator