Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Scenario:

When a User (let say Controller 1) creates a site using a site definition, "which already has a Custom List definition in it and different other things(like lists, webparts)"

Custom List: what it does is, You can create a item and assign it to any other controller or yourself.

Question: So what I want is, When the Site is being created, I just want to give "add New Items" / Edit List Items permission for that specific list to Controller 1 or the Controller "n" he gave permission for that specific site.

I know I need to add code somewhere while creating the site, but dunno how I gonna do that in this context :/

Cheers

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

I'm not 100% sure which users should be allowed to do what, but if you need to give difference Controllers control of difference list items then you could look at Setting item level security in an eventhandler

share|improve this answer
add comment

Here's an example of code I wrote to change the permissions on a list. This isn't list items, but you can probably figure out how to do that part :)

    SPList splDocuments = spwWeb.Lists["Documents"];
    splDocuments.BreakRoleInheritance(true);
    string strGroup = "[The name of your group]";
    RemoveAllPermissions(splDocuments, strGroup);

And then these functions:

    private SPPrincipal GetPrincipal(SPSite spsSite, string strGroupName)
    {
        SPPrincipal sppGroup = null;

        if (SPUtility.IsLoginValid(spsSite, strGroupName))
        {
            sppGroup = spsSite.RootWeb.EnsureUser(strGroupName);
        }
        else
        {
            foreach (SPGroup spgGroup in spsSite.RootWeb.SiteGroups)
            {
                if (spgGroup.Name.ToUpper(CultureInfo.InvariantCulture) ==
                    strGroupName.ToUpper(CultureInfo.InvariantCulture))
                {
                    sppGroup = spgGroup;
                    break;
                }
            }
        }
        return sppGroup;
    }

    private void RemoveAllPermissions(SPList splList, string strGroupName)
    {
        SPPrincipal sppPrincipal = GetPrincipal(splList.ParentWeb.Site, strGroupName);
        SPRoleAssignment spraRoleAssignment = splList.RoleAssignments.GetAssignmentByPrincipal(sppPrincipal);

        spraRoleAssignment.RoleDefinitionBindings.RemoveAll();
        spraRoleAssignment.Update();

        splList.Update();
    }
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.