MOSS07权限分配问题!
我们大家都直到,在SPS03和07里面 变化比较大的问题就是权限问题,
下面就是我操作07的权限分配代码,希望对各位开发人员有帮助
SPWeb web = (new SPSite("http://moss/sites/hello/subweb")).OpenWeb();
SPRoleDefinition newRole = new SPRoleDefinition();
newRole.Name = "My Role";
newRole.Description = "Role to view list items and pages.";
newRole.BasePermissions = SPBasePermissions.ViewListItems | SPBasePermissions.ViewPages;
if (!web.HasUniqueRoleDefinitions)
web.RoleDefinitions.BreakInheritance(true, true);
web.RoleDefinitions.Add(newRole);
SPList list = web.Lists["֪ͨ"];
if (!list.HasUniqueRoleAssignments)
list.BreakRoleInheritance(true);
SPRoleAssignment assignment = new SPRoleAssignment(web.EnsureUser("lhvm\wanghao")
assignment.RoleDefinitionBindings.Add(web.RoleDefinitions["My Role"]);
list.RoleAssignments.Add(assignment);