[Fixed] Server relative urls must start with SPWeb.ServerRelativeUrl"in reading web part properties!

Instantly Fixed: Server relative urls must start with SPWeb.ServerRelativeUrl”

2 comments

Loading

Server relative URLs must start with SPWeb.ServerRelativeUrl” in reading web part properties! – Recently I was working on, to the get web part properties details from the SharePoint site page using the PowerShell CSOM, then I got this error “Exception calling “ExecuteQuery” with “0” argument(s): “Server relative URLs must start with SPWeb.ServerRelativeUrl” in reading web part properties!:“. In this, SharePoint troubleshooting I will share how to fix this error.

 

"Server relative urls must start with SPWeb.ServerRelativeUrl"in reading web part properties!:
“Server relative URLs must start with SPWeb.ServerRelativeUrl” in reading web part properties!:

Before getting into the issue fixing let us understand what is Server Relative URL in SharePoint?

What is Server Relative URL in SharePoint?

In SharePoint, a Server Relative URL is a URL that is relative to the root of the SharePoint site or site collection. Unlike absolute URLs, which include the full path from the root of the web server, server relative URLs start from the root of the SharePoint site or site collection, omitting the domain and protocol.

Understanding Server Relative URLs

Components of a SharePoint URL

  1. Protocol: https://
  2. Domain: yourdomain.sharepoint.com
  3. Site Collection Path: /sites/YourSiteCollection
  4. Specific Resource Path: /Documents/yourfile.docx

Example Breakdown

  • Absolute URL: https://yourdomain.sharepoint.com/sites/YourSiteCollection/Documents/yourfile.docx
  • Server Relative URL: /sites/YourSiteCollection/Documents/yourfile.docx

Advantages of Using Server Relative URLs

  1. Portability: Server relative URLs are more portable because they do not include the domain and protocol, making it easier to move sites between environments (e.g., from a development to a production environment).
  2. Shorter and Cleaner: They are shorter and cleaner, which can simplify URL management and scripting.
  3. Consistency: When the SharePoint site is accessed via different domains or protocols, server relative URLs remain consistent.

Use Cases for Server Relative URLs

  1. Linking within SharePoint: When creating links within SharePoint pages, documents, or scripts, server relative URLs ensure that links are not broken if the site’s domain or protocol changes.
  2. API and Development: In SharePoint REST API calls and custom development, using server relative URLs can simplify code and make it more robust.

Examples of Server Relative URLs

  • Site URL: /sites/YourSiteCollection
  • Library URL: /sites/YourSiteCollection/Documents
  • Item URL: /sites/YourSiteCollection/Documents/yourfile.docx

How to Use Server Relative URLs in SharePoint

REST API Calls

When making REST API calls in SharePoint, you often need to use server relative URLs to specify the resource you’re interacting with.

Server relative URLs must start with SPWeb.ServerRelativeUrl”

How to fix the Exception calling “ExecuteQuery” with “0” argument(s): “Server relative URLs must start with SPWeb.ServerRelativeUrl” in reading web part properties!:?

Server relative urls must start with SPWeb.ServerRelativeUrl"in reading web part properties!
[Fixed] Server relative URLs must start with SPWeb.ServerRelativeUrl” in reading web part properties!

Solution: Server relative URLs must start with SPWeb.ServerRelativeUrl”

The issue was in this line, the way I was passing the PageRelativeURL parameter.

$PageRelativeURL="/SitePages/TestWPPage.aspx"

#Parameters value
$siteURL="globalsharepoint2020.sharepoint.com/sites/CustomSearchRND"

$PageRelativeURL="/SitePages/TestWPPage.aspx"
$downloadLocation=$directoryPathForFileDownloadLocation;
$userName = "YourSPOUsername@tenant.domain.com"
$passWord = "YourSPOPassword"
#Parameters ends here.

#Calling the GetWebPartPropertyDetail function and passing the parameters.
GetWebPartPropertyDetails $siteURL $PageRelativeURL $userName $passWord

Change the $PageRelativeURL=”/SitePages/TestWPPage.aspx” to like below:

$PageRelativeURL="/sites/CustomSearchRND/SitePages/TestWPPage.aspx"

Note:

In the page relative URL, we need to pass the URL in the below format:

"/sites/yoursitename/SitePagesOrPages(library)/yourpage.aspx"

Server relative URLs must start with SPWeb.ServerRelativeUrl error in GetFolderByServerRelativeUrl REST API

We will get the server relative URLs must start with SPWeb.ServerRelativeUrl error while we call the GetFolderByServerRelativeUrl REST API either from Power Automate (Send HTTP request SharePoint), Postman Tool, Dot Net, PowerShell, or any other coding.

Using the below API URL just try to browse any document library for testing, and we will get the below-mentioned error:


globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/web/GetFolderByServerRelativeUrl('/Shared%20Documents')/Files

System.Argument Exception in Server relative urls must start with SPWeb.ServerRelativeUrl error
System.Argument Exception in Server relative URLs must start with SPWeb.ServerRelativeUrl error

In the above example, we have passed the API URL like the below:

SiteURL/_api/web/GetFolderByServerRelativeUrl('/Shared%20Documents')/Files

And our site URL is as below:

globalsharepoint2020.sharepoint.com/sites/GSDRnD

So, inside the GetFolderByServerRelativeUrl we need to pass the path as below:

(‘/sites/GSDRnD/Shared%20Documents’)

Now, if we construct the API URL as below

globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/web/GetFolderByServerRelativeUrl('/sites/GSDRnD/Shared%20Documents')/Files

Then, we will get successful results.

GetFolderByServerRelativeUrl - Server relative urls must start issue fixed
GetFolderByServerRelativeUrl – Server relative URLs must start issue fixed

Summary: ServerRelativeUrl error in SharePoint Online

Hence, in this troubleshooting, we have learned about how to fix the Exception calling “ExecuteQuery” with “0” argument(s): “Server relative URLs must start with SPWeb.ServerRelativeUrl” in reading web part properties!: error.

See Also: SharePoint Online PowerShell tutorial

You may also like the following SharePoint PowerShell tutorials:

 

 

About Post Author

2 comments on “Instantly Fixed: Server relative urls must start with SPWeb.ServerRelativeUrl””

Do you have a better solution or question on this topic? Please leave a comment