Note that there are some explanatory texts on larger screens.

plurals
  1. POSharepoint: web part programmatically changing permissions, cannot get the changes to persist
    text
    copied!<p>I'm writing a visual web part in visual studio for sharepoint 2010. The whole point of this web part is to change permissions around at the click of a button. I am able to access the permissions and output them to the screen. I'm able to change the permissions in the objects that I have, and then show the changed permissions on the screen. My problem is, after everything is done, no actual permissions have been changed.</p> <p>webpart.TargetLibrary is a text field, inputted elsewhere as the name of the library I wish to investigate.</p> <pre><code>SPListCollection docLibs = m_SharePointWeb.GetListsOfType(SPBaseType.DocumentLibrary); SPDocumentLibrary targetLib = (SPDocumentLibrary)(docLibs[webPart.TargetLibrary]); SPListItemCollection libFolders = targetLib.Folders; SPListItem folderItem = libFolders[0]; SPRoleAssignmentCollection folderRoles = folderItem.RoleAssignments; SPRoleAssignment roleAssign = folderRoles[0]; SPRoleDefinitionBindingCollection spRDBC = roleAssign.RoleDefinitionBindings; SPRoleDefinition Contribute = spRDBC[0].ParentWeb.RoleDefinitions["Contribute"]; folderItem.RoleAssignments[0].RoleDefinitionBindings.Add(Contribute); folderItem.Update(); </code></pre> <p>This is a somewhat simplified version - the original had some for loops and various bits of other code doing other things. Regardless, by everything I've been able to piece together from looking online, this code <em>should</em> add "Contribute" privs to the first role on the list in the first folder. As I mentioned, it does so to the local objects, but has no permanent effect. The Update() call appears to do nothing, and I'm not certain it's meant to be there in this case. I tried UpdateOverwriteVersion() - that doesn't do anything either. Any suggestions on what I might be doing wrong would be appreciated.</p> <p>As a side note, it's not nearly so much of an issue, but I can't help the feeling that there's a more efficient and straightforward way to get a web object so that I can acquire role definitions by name. Any advice on that matter would also be appreciated.</p> <p>Edit: solution moved to answer, below.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload