I'm tring to get the file by relative URL . I"m usig sharepoint onligne . and i get this error:

Server relative urls must start with SPWeb.ServerRelativeUrl

here is the code:

$web = $ctx.Web
  $PageLayoutName = $pageLayoutContentType
  $items = $web.GetFileByServerRelativeUrl($PageLayoutName)
  • 1
    what values are you using in $pageLayoutContentType and $PageLayoutName ? It needs to be relative url like /sites/test/_catalogs/master/mypagelayout.aspx Commented Nov 22, 2017 at 9:20

1 Answer 1


You can check a page layout server relative url with Rest API, for example, get a pagelayout server relative url in Pages Library:


enter image description here

And use this value in $web.GetFileByServerRelativeUrl method

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.