Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6099891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:19:29+00:00 2026-05-23T13:19:29+00:00

Struggling to set permissions on a listitem… everything appears to be working fine.. no

  • 0

Struggling to set permissions on a listitem… everything appears to be working fine.. no errors.. but when checking the document on sharepoint.. the permission groups im adding are not set.

any idea what i’m missing?

sharepoint dev is a real nightmare!

public void SetDocumentPermission(ListItem doc, List<Group> newGroup)
    {
        using (var clientContext = GetNewContext())
        {
            var rdb = new RoleDefinitionBindingCollection(clientContext);
            var rootWeb = clientContext.Web;
            clientContext.Load(rootWeb);
            clientContext.ExecuteQuery();

            foreach (var group in newGroup)
            {
                try
                {
                    var usr = (Principal)group;
                    var roll = rootWeb.RoleDefinitions.GetByType(RoleType.Reader);

                    clientContext.Load(roll);
                    clientContext.ExecuteQuery();

                    rdb.Add(roll);

                    if (!doc.HasUniqueRoleAssignments)
                    {
                        doc.BreakRoleInheritance(true, true);
                    }

                    doc.RoleAssignments.Add(usr, rdb);

                    doc.Update();

                    clientContext.ExecuteQuery();   
                }
                catch (Exception exception)
                {
                    throw new ApplicationException(exception.Message);
                }

            }

        }
    }

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:19:29+00:00Added an answer on May 23, 2026 at 1:19 pm

    ok i resolved this problem by setting the Client context at class level rather than method.
    i’m not sure if there is some sort of binding done between listitem and the ctx.. but as i returned the listitem from another method (which also had a using around the ctx) and passed it into this permissions method.. the listitem appeared to lose it’s connection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been struggling to set the value of JHTML Area. But no luck.
I'm struggling through getting everything set up here, I have my extension installed in
I'm struggling with this one. I need to set the permissions of the App_Data
I am struggling with the best way to report errors in a set of
Im playing around with NHibernate 3 alpha but struggling to set up my SessionFactory.
I am struggling to set an background image for an QPushButton. No Success till
I'm struggling with how I would set up a database for a situation where
I am struggling with getting Inno Setup to set the check box to true
I have been struggling to make a set of reports that gives the sum
I have been struggling with this for a while now. given a set of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.