I am trying to create a sub-site and some predefined lists in the existed site collection. I am successfully created the sub site in the site. But Now i want to create lists in that newly created site. But I am not able to get the context of the newly created site. How to get the context of the newly created site from the sharepoint app. I am using auto hosted app model for office 365 account. Finally I tried in this old way.

using (ClientContext subSiteContext = new ClientContext(new Uri(newWeb.Url)))
   DeployLists(subSiteContext, templateConfig);

But I am getting exception as

The remote server returned an error: (403) Forbidden.

How to get the context of sub site.

2 Answers 2


You should be able to create a context for a subsite, just by using subsite's url.

Since you say that it is a newly created site, maybe it hasn't been fully provisioned yet and hence you get the error. Can you reproduce the behaviour on another subsite or on the next day with the same one? Can you access the site via GUI?

Can you try just the steps below?

ClientContext ctx = new ClientContext(url);
ctx.Credentials = new SharePointOnlineCredentials(userName, securestring);

Do you have the permissions for the new site?

And, since it's been already a year :), if you managed to find another solution, can you post it here?

var clientContext = new SP.ClientContext.get_current();
var rootWeb = clientContext.get_site().get_rootWeb();
var webInfo = new SP.WebCreationInformation();




clientContext.executeQueryAsync(onSuccess, OnFailure);
  • Hi and welcome to the SharePoint StackExchange community! Could you give a little detail to explain your method?
    – thanby
    Jan 3, 2014 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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