Document Permissions
Good afternoon, I am using Sharepoint 2007. How can I post a document via a hidden webpart or document library and add permissions to it. It is a hidden link so I have setup audience targeting. For example how would I grant say team one read only access and team two full control over the document? Thank you for any help given.
April 13th, 2010 3:15am

You can set this up via an event handler. Some example code is here: SPWeb web = properties.Web; string groupName = web.Properties["SetDevelopmentPermissions.Group"]; string groupDesc = web.Properties["SetDevelopmentPermissions.Group.Desc"]; string colName = web.Properties["SetDevelopmentPermissions.ColumnName"]; try { if (web.SiteGroups[groupName] == null) { } } catch (Exception ex) { SPGroup owner = web.AssociatedVisitorGroup; web.SiteGroups.Add(groupName, owner, web.SiteAdministrators[0], groupDesc); } SPGroup group = web.SiteGroups[groupName]; SPListItem li = properties.ListItem; if (properties.AfterProperties[colName].ToString().ToLower() == groupName.ToLower()) { if (!li.HasUniqueRoleAssignments) { li.BreakRoleInheritance(false); } //remove any permissions while (li.RoleAssignments.Count > 0) li.RoleAssignments.Remove(0); //set full control permissions SPRoleDefinition RoleDefinitionRdr = web.RoleDefinitions.GetByType(SPRoleType.Administrator); SPRoleAssignment roleAssignment = new SPRoleAssignment((SPPrincipal)group); roleAssignment.RoleDefinitionBindings.Add(RoleDefinitionRdr); //adds permissions to item li.RoleAssignments.Add(roleAssignment); li.Update(); } else { //ensure the object is set to inherit li.ResetRoleInheritance(); li.Update(); } ChrisChris Givens CEO, Architecting Connected Systems Blog Twitter
Free Windows Admin Tool Kit Click here and download it now
April 13th, 2010 3:49am

Thank you very much Chris, We had our Intranet site setup by an outside company. I am able to admin the site via a web browswer but no actual coding is done by myself. Is the way you described the only way? Basically I just need to know if single documents can have security rules addes. Thank you.
April 13th, 2010 4:42am

>Basically I just need to know if single documents can have security >rules added. Better in that case to ask that question in your (original post). It's a pity because Chris's useful answer to your actual question (which would have meant me moving this question to the programming forum) now gets "lost". I'm moving this to the Administration forum as how to add security to a single document is standard functionality. Open a view of the document library that contains the document; hover the cursor on the line of the document's listing after the name and select the drop-down you then see; one of the options is document permissions. Note that it's wise to ensure that people you add here have rights to the site containing the doc lib+document. Also that you need to upload the document first before you can do this, so there is a short period with no restrictions on access.FAQ sites: (SP 2010) http://wssv4faq.mindsharp.com; (v3) http://wssv3faq.mindsharp.com and (WSS 2.0) http://wssv2faq.mindsharp.com Complete Book Lists (incl. foreign language) on each site.
Free Windows Admin Tool Kit Click here and download it now
April 13th, 2010 5:35am

Mike's right, the answer is yes and he outlines it nicely. Sorry about the code post, didn't check it closely before I posted. ChrisChris Givens CEO, Architecting Connected Systems Blog Twitter
April 13th, 2010 5:49am

I thought I replied so sorry if this is a repost... Thank you very much Mike and Chris, it was my first post so I was not sure where to post it. I will be more careful next time. I really appreciate both of you taking the time to help me. I have some more questions and will hopefully ask them in the right place. Thanks again.
Free Windows Admin Tool Kit Click here and download it now
April 14th, 2010 5:34am

Also that you need to upload the document first before you can do this, so there is a short period with no restrictions on access. To eliminate the gap of unrestricted access upload the document to a restricted folder; set the permissions for the file; then, move the file to where you want it to be. Jacob
July 7th, 2010 6:14pm

What level of permissions does a user need to have in order to be able to set document permissions? Full access?
Free Windows Admin Tool Kit Click here and download it now
September 9th, 2010 3:32am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics