Geeks With Blogs
Madhawa Learns To Blog : C#, Java .net, c#, java,sql, OOAD and more mad memory dumps...

        /// <summary>
        /// Add Permission Level to a Sharepoint user group collection
        /// </summary>
        /// <param name="spWeb">The sp web.</param>
        /// <param name="permissionName">Name of the permission.</param>
        /// <param name="groupCollection">The group collection.</param>
        public static void AddPermissionsToGroupCollection(SPWeb spWeb, string permissionName, string[] groupCollection)
                    //Allow updating of some sharepoint lists, (here spUsers, spGroups etc...)
                    spWeb.AllowUnsafeUpdates = true;

                    SPRoleDefinition roleDefinition = spWeb.RoleDefinitions[permissionName];

                    foreach (string group in groupCollection)

                        SPGroup spGroup = spWeb.Groups[group];

                        SPRoleAssignment roleAssignment = new SPRoleAssignment(spGroup);
                        SPRoleDefinitionBindingCollection roleDefBindings = roleAssignment.RoleDefinitionBindings;



                catch (Exception ex)
                    //Error handling logic should go here
                    throw ex;
                    spWeb.AllowUnsafeUpdates = false;


Ok this is it.

Well... I called above method from "FeatureActivated" event of a feature. For "FeatureDeactivating" event I tried to achieve the contrary to this, delete a permission level from a user group. But didn't succeed. :( 

If you have any idea pls let us know.Thanks in advance.

Posted on Monday, August 17, 2009 11:06 PM .net , .net 3.0 , MOSS , MOSS Object Model | Back to top

Comments on this post: Add Permission Level to a Sharepoint user group collection

# re: Add Permission Level to a Sharepoint user group collection
Requesting Gravatar...
You have to use BreakRoleInheritance(false) if you haven't unique role assignments.
thanks !
Left by saranga on Dec 08, 2009 2:09 AM

Your comment:
 (will show your gravatar)

Copyright © Madhawa Karunaratne | Powered by: