3

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

1

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);
ctx.ExecuteQuery();

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?

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

webInfo.set_webTemplate('STS#0');
webInfo.set_description('SiteDescription');
webInfo.set_title('SiteTitle');
webInfo.set_url('SiteUrl');
webInfo.set_language(1033);

rootWeb.get_webs().add(webInfo);
rootWeb.update();

clientContext.load(rootWeb);

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

Your Answer

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

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