1

I am trying to access the Root site list using the sub site client context. But when I try to execute the clientcontext it gives Access Denied error.

I tried to create new clientcontext by passing the accessToken as well but no success. (Referred: This)

Below is the code:

clientContext.Load(clientContext.Site);
clientContext.ExecuteQuery();
string siteUrl = clientContext.Site.Url;
Uri webUri = new Uri(siteUrl);
string realm = TokenHelper.GetRealmFromTargetUrl(webUri);
string accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, webUri.Authority, realm).AccessToken;
using (var cc = TokenHelper.GetClientContextWithAccessToken(siteUrl, accessToken))
{
    cc.Load(cc.Web);
    cc.ExecuteQuery();
}

Here, clientContext is the context of Sub-Site and cc is the context of Root site.

How can I access the cc using clientContext?

1 Answer 1

0

Found a solution!!

We can access the Root site lists from subsite using below.

clientContext.Site.RootWeb.Lists

No need to create a new context of the Root site.

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.