SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm currently building a Silverlight web part on SharePoint 2010. The issue I have, maybe is too trivial for me, is that I have a list, lets say its, I want to retrieve the site url, in this case: . The url can vary depending on the depth of the subsite. I've try using the ClientContext.Current but without success.

Any help would be appreciated!

share|improve this question
up vote 1 down vote accepted

You need to load the required properties. Unlike server side object model, context.web will be largely empty until you explicitly load the data.

context = ClientContext.Current;   
web = context.Web;
context.Load(web, w => w.Title, w => w.Description, w => w.ServerRelativeUrl);   
context.ExecuteQueryAsync(OnSiteLoadSuccess, OnSiteLoadFailure);

So here you can access web.ServerRelativeUrl method in OnSiteLoadSuccess method.

share|improve this answer
I've tried that, but always return the root "/" as ServerRelativeUrl. I think my issue is that the XAP file is hosted in the and return always the root based on this address, not from where the webpart is. – Gabriel Mongeon Jan 12 '12 at 12:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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