Server relative URLs must start with spweb.serverrelativeurl in SharePoint

In this SharePoint tutorial, I will explain how to fix the error “server relative urls must start with spweb.serverrelativeurl” that comes while working with CSOM SharePoint.

server relative urls must start with spweb.serverrelativeurl

Recently, I was working with an ASP.net web application using Visual Studio. 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 running this CSOM code, an error occurred: “SharePoint Server relative URLs must start with SPWeb.ServerRelativeUrl.” The error message is shown in the screenshot below.

server relative urls must start with spweb.serverrelativeurl csom

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

This is how to fix the error, server relative urls must start with spweb.serverrelativeurl that comes while working with CSOM SharePoint.

You may also like:

See also  SharePoint Rest API [Complete Tutorial With Examples]
>