SharePoint Server relative urls must start with SPWeb.ServerRelativeUrl csom

In this SharePoint PnP tutorial, We will discuss the solution of an error as “SharePoint Server relative urls must start with SPWeb.ServerRelativeUrl“.

Recently, I was working with PnP SharePoint ASP.NET Web Application in Visual Studio 2017. There, I have added a Content Search Web Part using CSOM. To add this web part, You have to retrieve the Page URL. I was adding this page URL as [“/Pages/WebPartPageName.aspx”].

While I was running this CSOM code, an error occurred as “SharePoint Server relative urls must start with SPWeb.ServerRelativeUrl“. You can see the error message in below screenshot.

server relative urls must start with spweb.serverrelativeurl csom
server relative urls must start with spweb.serverrelativeurl csom

SharePoint Server relative urls must start with SPWeb.ServerRelativeUrl

The Solution of this above error is: You should pass the Server Relative URL as “/sites/SiteName/Pages/WebPartPageName.aspx “. Once you will pass this type of Server relative URL Path and again run the code, then it will execute and give the appropriate result.

You may like following SharePoint PnP csom tutorials:

Here in this SharePoint PnP tutorial, We discussed the solution of an error as “SharePoint Server relative urls must start with SPWeb.ServerRelativeUrl“. By using this above solution, You can overcome this type of issue.

>