0

I'm trying to check out file which is located inside document library under sub site.

Site URL : mymainsite/subsite/subsite/My Library/test.xlsx

I'm using below PowerShell script

function CheckOutFile($filePath) {
    Write-Host "CheckOut file is in process"


    $response = PostRequest ("/_api/web/getFileByServerRelativeUrl('/My Library/test.xlsx')/CheckOut()") (ConvertTo-Json @{ 
        __metadata = @{ type= "SPFile" }
        ServerRelativeUrl = "/My Library/test.xlsx"
    })
}

Note: If I'm trying to checkout in root site library then it is working fine when I'm referring to subsite library it showing below error.

enter image description here

What I'm doing wrong here :(

1 Answer 1

0

To refer library under subsite we need to specify relative url two times like below:

function CheckOutFile($filePath) {
    Write-Host "CheckOut file is in process"


    $response = PostRequest ("/_api/web/getFileByServerRelativeUrl('/subsite/subsite/My Library/test.xlsx')/CheckOut()") (ConvertTo-Json @{ 
        __metadata = @{ type= "SPFile" }
        ServerRelativeUrl = "/My Library/test.xlsx"
    })
}

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.