0

I'm trying to enumerate all sites that a user has access to underneath a given site in sharepoint. For example, given I've authenticated to https://offtechsmith.sharepoint.com/teams/teamsite, I want to enumerate the two subsites https://offtechsmith.sharepoint.com/teams/teamsite/dev-testing and https://offtechsmith.sharepoint.com/teams/teamsite/dev-testing-2.

I'm authenticating using the scope Web.Read when logging in via OAuth.

The code I'm using is

using ( ClientContext clientContext = TokenHelper.GetClientContextWithAccessToken( sharepointUrl.AbsoluteUri, accessToken ) )
{
    WebCollection webCollectionResult = clientContext.Web.GetSubwebsForCurrentUser( new SubwebQuery() );
    IEnumerable<Microsoft.SharePoint.Client.Web> result = clientContext.LoadQuery( webCollectionResult ); 
    clientContext.ExecuteQuery();
}

When I do that I get back the following error: Access denied. You do not have permission to perform this action or access this resource.. Is there a different scope I should be requesting to make this call?

0

You need read permissions on the site collection to view other sites in it. You can read up more on the app permission model here.

Alternatively, you can use REST, and use the search endpoint, which will automatically trim the results for you.

  • I'm doing on the fly permission request so I don't think I can ask for the Site.Read scope since most users (non-admins) won't be able to grant it. What would a search query look like for subsites? – Evan Sep 26 '14 at 15:19
  • I believe you can use CSOM for search as well. The query text would look like this: contentclass:STS_Web Path:https://offtechsmith.sharepoint.com/teams/teamsite. It retrieves all Webs from the Site that the user has access to. – wjervis Sep 26 '14 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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