Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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 http://www.mysite.com/subsite/anothersubsite/Lists/mylist/AllItems.aspx, I want to retrieve the site url, in this case: http://www.mysite.com/subsite/anothersubsite . 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

1 Answer 1

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 mysite.com/SomeFolder/MyApp.xap 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.