Getting access denied error during feature activation in subsite of Group site using CSOM

Yuvraj Patil 441 Reputation points
2023-01-17T11:57:32.1333333+00:00

Hello,
I am trying to activate feature on subsite of group site using CSOM where I am getting access denied error.
Steps:

  1. Created subsite in Group Site 01
  2. Using CSOM cached all feature ids of subsite from Group Site 01
  3. Created subsite in Group Site 02 using CSOM
  4. trying to add cached features in subsite from Group Site 02
  5. On 4th step getting error.
FeatureDefinitionScope featureDefinitionScope = FeatureDefinitionScope.None;

foreach (var featureID in cachedFeatures)
   web.Features.Add(featureID, true, featureDefinitionScope);

// web object points to subsite from Group site 02

web.Update();
clientContext.ExecuteQuery();

Thanks in Advance !

Microsoft 365 and Office | SharePoint Server | For business
Microsoft 365 and Office | SharePoint | Development
Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2023-01-24T06:31:17.0766667+00:00

    Hi @Yuvraj Patil

    I'm glad to hear you solve the problem ,if you have any issue about SharePoint, you are welcome to raise a ticket in this forum.

    By the way, since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others." and according to the scenario introduced here: Answering your own questions on Microsoft Q&A, I would make a brief summary of this thread:

    Getting access denied error during feature activation in subsite of Group site using CSOM

    Issue Symptom:

    Activate feature on subsite using CSOM and get access denied error

    Current status:

    Move the update line up and it solved the issue.

    // other code
    
    web.Update();
    
    FeatureDefinitionScope featureDefinitionScope = FeatureDefinitionScope.None;
    
    foreach (var featureID in cachedFeatures)
       web.Features.Add(featureID, true, featureDefinitionScope);
    
    // web object points to subsite from Group site 02
    
    clientContext.ExecuteQuery();
    

    You could click the "Accept Answer" button for this summary to close this thread, and this can make it easier for other community member's to see the useful information when reading this thread. Thanks for your understanding!

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2023-01-18T05:37:31.4233333+00:00

    Hi @Yuvraj Patil

    The user has limited permissions, or no permissions, for the site collection that contains the subsite 02 while the same user have Full Control permissions for the subsite 02 might cause Access Denied. To resolve this issue, have a site collection administrator permission to activate the feature on the subsite. Or add the affected user to the Hierarchy Managers group for the site collection that contains the subsite. The user must have access to the parent site collection through the Hierarchy Managers group to activate or deactivate the SharePoint Server Publishing site feature for the subsite.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.