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

How can i access a list in a subsite?

function Read () {

var caml = "<View><ViewFields><FieldRef Name='Title'/><FieldRef Name='ID'/><RowLimit>2</RowLimit></ViewFields ></View>";

var context = new SP.ClientContext.get_current();
var items = contextManagement.get_web().get_lists().getByTitle("Posts");

var query = new SP.CamlQuery();
results = items.getItems(query);


context.executeQueryAsync(Function.createDelegate(this, this.Div_befuellen), Function.createDelegate(this, this.onFailure));


This is the code, i all ready use. But how i has to change the code when the list is not on a subsite (Root\SubSite)?

I like to show News on the start page of a site collection but the news list is on a subsite (SharePointServer\News) from the sitecollection.

Thanks for your help Stefan

share|improve this question
This is not directly an answer to your question, but I am curious why you aren't using the built in List View web part or even the Content Query web part? CQWP even lets you point it directly at the list you wish to use, even if it is in a subsite. – Dave Wise Dec 10 '12 at 20:51
Thanks for your help Dave. Because the list is in the subsite of the sitecollection and i want to show the items on a page in the root site. I dont cant finde the content query webpart in the foundation. And i have to use the foundation. – Stefan Dec 10 '12 at 21:12

Instead of using SP.ClientContext.get_current() use

var clientContext = new SP.ClientContext('server realtive url of the web');

Check this documentation for more info.

share|improve this answer
Thanks for your help. Code like this? Where News is a subsite. var context = new SP.ClientContext("SPServer/News"); var items = contextManagement.get_web().get_lists().getByTitle("Posts"); – Stefan Dec 10 '12 at 21:14
var context = new SP.ClientContext('/News'); var list = context.get_web().get_lists().getByTitle("posts"); – sssreddy Dec 10 '12 at 21:46
thanks for your help – Stefan Dec 10 '12 at 22:13

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.