2

I am using the SharePoint Object Model to create new sites programmatically (with a custom web part). It works fine but I am wondering if it is possible to grant permission for groups as well?

When I create the site I have set it to not inherit permission:

newWeb = SPContext.GetContext(HttpContext.Current).Web.Webs
    .Add(siteUrl, siteName, siteDescription, (uint)1033, siteTemplate, true, false);

In the GUI I can then go to Site Actions (on the newly created site) -> Grant Permission -> search for groups in the parent site and then grant permission for this group. So, in the parent site myGroup can have Full Access permissions but in this site I can set it to Contribution or whatever. Is it possible to do this when I create the site or just after (programmatically)?

2 Answers 2

1

Here is an example Add Permission Level to a Sharepoint user group collection

0

Another great references can be found here: http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/08/25/how-to-create-a-group-in-sharepoint.aspx http://dotnetmafia.com/blogs/dotnettipoftheday/archive/2010/03/08/a-simple-way-to-programmatically-create-sharepoint-security-groups.aspx

Just remember: if you want to use a Feature Event Receiver, you should change feature activation of the solution (solution properties) to "Without activation", and to be able to deploy the Feature Event Receiver, set the Sandbox deployment to false.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.