I've created an event handler that fires when a new item is created in
a list, and automatically creates a new subsite based on the
parameters to the list.
This works almost fine, but I have two issues that I hope someone can
help me with.
1) Permissions
Since my subsite does not inherit permissions I need to create the
Owner, Member and Visitors groups and add the appropriate
permissionlevels. I'm having problem adding the creator to the Owner
group.
My code:
// Add current user to owner group
SPUser user = parentWeb.Users.GetByID(properties.CurrentUserId);
newWeb.AssociatedOwnerGroup.AddUser(user);
newWeb.AssociatedOwnerGroup.Update();
The code runs, and I get no error, but the user is not added to the
group.
I hope some of you might have a tip for me?
2. Navigation
I would like the subsites to be added to the parent site's top link
bar that same way that they are when they are created using the ui
wizard and you choose to display this site in the top navigation bar
of the parent area.
I'm able to create a new node in the parent TopNavigation bar, but if
I do this the link is visible to everyone and not just the users that
have access to the subsite.
My code:
// Display settings
newWeb.Navigation.UseShared = true;
// Add site to top navigation if parent does not inherit navigation
if (!newProject.ParentWeb.Navigation.UseShared)
{
SPNavigationNode node = new SPNavigationNode(newProject.Title,
newProject.ServerRelativeUrl);
SPNavigationNode addedNode =
newProject.ParentWeb.Navigation.TopNavigationBar.AddAsLast(node);
addedNode.IsVisible = true;
addedNode.Update();
}
newProject.Update();
Any help is much appreciated.
Regards
Elin Kolloen