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 – Gautam Sheth Nov 22 '17 at 9:20

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, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.