I'm trying to retrieve a relative url from a SP.Web I get my sp.web from a SP.list with

SPWeb test = listNL.ParentWeb;

When I try to get the url I got an exception:

test.ServerRelativeUrl' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException


Do you know a solution to retrieve the relative url from the list?


This error occurs since ServerRelativeUrl property of Web object has not been loaded.

You have to explicitly specify to load ServerRelativeUrl property:

var list = ctx.Web.Lists.GetByTitle(listTitle);
ctx.Load(list,l => l.ParentWeb.ServerRelativeUrl);
var webUrl = list.ParentWeb.ServerRelativeUrl;

or use List ParentWebUrl property:

var list = ctx.Web.Lists.GetByTitle(listTitle);
var webUrl = list.ParentWebUrl;

to retrieve Web ServerRelativeUrl property.

How to retrieve List server-relative Url via CSOM

var list = ctx.Web.Lists.GetByTitle(listTitle);
ctx.Load(list,l => l.RootFolder.ServerRelativeUrl);
var listUrl = list.RootFolder.ServerRelativeUrl;
|improve this answer|||||
  • Thanks for yor reply but do you have a solution to test if list.getybytitle exist. I test if it's not null but it's never null as it doesn't exist – user1898765 Jul 23 '14 at 11:29

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.