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 6709001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:49:42+00:00 2026-05-26T07:49:42+00:00

I am trying to manipulate SPListItem permissions on folders in a document library but

  • 0

I am trying to manipulate SPListItem permissions on folders in a document library but I can’t seem to add any new permissions, though removing security inheritance works beautifully.

I’ve done my best to create a slimmed down version of the code for testing purposes. The function GetListItem returns the SPListItem we are working with based on the URL. The item.BreakRoleInheritance(False) works great and I’ve verified properly breaks inheritance and clears out any permissions, I’ve also tried it with the True flag and verified that all original permissions are copied from the parent.

The code below throws no exceptions and as far as I can tell appears to work fine, until I check the actual permissions on the folder in my document library and see that “Viewers” is not listed.

Code:

    Dim item As SPListItem = GetListItem(URL)

    If item Is Nothing Then
        Exit Sub
    End If

    Dim spGrp = SharePointWeb.SiteGroups("Viewers")
    Dim spRole As SPRoleDefinition = SharePointWeb.RoleDefinitions("Read")

    Dim roleAssignment As New SPRoleAssignment(spGrp)
    roleAssignment.RoleDefinitionBindings.Add(spRole)

    SharePointWeb.AllowUnsafeUpdates = True

    item.BreakRoleInheritance(False)
    item.RoleAssignments.Add(roleAssignment)
    item.Update()

    SharePointWeb.AllowUnsafeUpdates = False

I have tried wrapping this code in a call to SPSecurity.RunWithElevatedPrivileges but it didn’t make any difference. The creation of my SPSite/SPWeb objects is wrapped in a call to SPSecurity.RunWithElevatedPrivileges and I have other code that runs which finds/deletes/updates attributes on folders/etc… with this existing code; just permissions don’t want to work.

References:
– http://moldenco.blogspot.com/2007/05/spsecurityrunwithelevatedprivileges-to.html
– How to give an SPGroup permissions for an SPItem?
– http://blogs.msdn.com/b/joelo/archive/2007/10/05/sharepoint-roles-assignments.aspx

  • 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-26T07:49:42+00:00Added an answer on May 26, 2026 at 7:49 am

    Through researching the issue and trying a veriety of different methods I happened across an exception, “Operation is not valid due to the current state of the object” which occured in SPWebEnsureSPControl.

    I did some googling and found this forum post http://social.msdn.microsoft.com/forums/en-US/sharepointdevelopment/thread/32869ac6-4f47-46b8-accf-f56966ac9581 which lead me to modify my code. I made System.Web.HttpContext.Current = Nothing the first line of code after calling SPSecurity.RunWithElevatedPrivileges and everything started working.

    So my code looks something like (using an anonomous delegate):

        SPSecurity.RunWithElevatedPrivileges(Sub()
                                                 System.Web.HttpContext.Current = Nothing
                                                 ........
                                             End Sub)
    

    From what I read System.Web.HttpContext.Current still has connections to your non-elevated account and by setting it to null it gets rid of the problem.

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

Sidebar

Related Questions

I'm having trouble trying to manipulate music using buttons I can't seem to make
I'm trying to manipulate a tableViewRow inside a TableView but I can't find where
I'm trying to manipulate a xml file from sharepoint document library with powershell. Unfortunately
I am trying to manipulate SharePoint's default calendar to add, edit and delete items
I'm looking for a good python library to manipulate subversion repositories. I'm trying out
Trying to manipulate a table with jQuery, and I just cannot seem to get
I am trying to manipulate a requested document in the WPF WebBrowser-control. I already
I'm trying to manipulate the XUL elements in the Firefox add-on page using the
I am trying to manipulate a string so that any quotes () within <a
I am trying to manipulate a file and create a new folder from within

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.