Wednesday, June 17, 2015

Set Permission to Document Library Programmatically



SPRoleAssignment roleassignment;
SPRoleDefinitionCollection webroledefinitions = web.RoleDefinitions;
SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists[“LibraryName”];
SPUser oUser = web.EnsureUser(“domain\\loginname”);
roleassignment = new SPRoleAssignment(oUser);
roleassignment.RoleDefinitionBindings.Add(webroledefinitions[“Read”]);
docLib.RoleAssignments.Add(roleassignment);
docLib.Update();

No comments:

Post a Comment