Here is code which is very simple will make you better understanding .
using (SPSite spSite = new SPSite("http://servername:Portnumber/"))
{
using (SPWeb spWeb = spSite.OpenWeb())
{
SPList spList = spWeb.Lists["AgeRating"];
//Get all roles from the existing list
SPRoleAssignmentCollection coll = spList.RoleAssignments;
SPListCollection lists = spWeb.Lists;
// create new Generic list called "MyList"
if (!spWeb.Lists.Cast
{
spWeb.AllowUnsafeUpdates = true;
lists.Add("MyList", "My list Description", SPListTemplateType.GenericList);
spWeb.AllowUnsafeUpdates = false;
}
SPList targetList = spWeb.Lists["MyList"];
foreach (SPRoleAssignment role in coll)
{
targetList.BreakRoleInheritance(false);
spWeb.AllowUnsafeUpdates = true;
targetList.RoleAssignments.Add(role);
}
spWeb.AllowUnsafeUpdates = false;
}
}
2 comments:
Grateful to check out your website, I seem to be ahead to more excellent sites and I wish that you wrote more informative post for us. Well done work.
Hello RajKamal,
Is this within the same site? Can you please give details on where to put new list name and so on.
Post a Comment