
Buildout
253
{
webApp.Properties.Add(key, site.ID);
webApp.Update();
}
//check for the admin group’s existence
SPGroup admins = null;
try
{
admins = site.RootWeb.SiteGroups[“Site Creation Administrators”];
}
catch { ; }//eat the error if the group can’t be found
if (admins == null)
{
//Create the administrators group
site.RootWeb.SiteGroups.Add(
“Site Creation Administrators”,
site.RootWeb.SiteAdministrators[0],
null,
“This group has full control over site creation.”
);
admins = site.RootWeb.SiteGroups[“Site Creation Administrators”];
//grant them full control over the site
SPRoleAssignment assignment = new SPRoleAssignment(admins);
assignment.RoleDefinitionBindings.Add(
site.RootWeb.RoleDefinitions[“Full Control”]
);
site.RootWeb.RoleAssignments.Add(assignment);
site.RootWeb.Update();
}
//Get an SPUser object representing all users
SPUser allusers =
site.RootWeb.EnsureUser(“NT AUTHORITY\\authenticated users”);
//Add to the associated visitors group
if (site.RootWeb.AssociatedVisitorGroup != null)
{
try
{
site.RootWeb.AssociatedVisitorGroup.AddUser(allusers);
site.RootWeb.AssociatedVisitorGroup.Update();
}
catch { ; }//ignore the error if allusers has already been added
//grant visitors access to the requests list
SPRoleAssignment assignment =
new SPRoleAssignment(site.RootWeb.AssociatedVisitorGroup);
assignment.RoleDefinitionBindings.Add(
continues
105054c09.indd 253 1/10/12 3:34 PM