Programming Item Security on WSS 3 / Moss
I got this code on the internet how to setting permission on WSS/MOSS folder or it could be item too can be set the security.
/* seeting permision */
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
namespace ListItemPerms
{
class Program
{
static void Main(string[] args)
{
SetListItemPerms();
}
static void SetListItemPerms()
{
//Get SPWeb object
SPSite Site = new SPSite("http://<url>"); //e.g., "http://myserver/mysite"
SPWeb Web = Site.OpenWeb();
//Get Role Definition from SPWeb
SPRoleDefinition
RoleDefinition =
Web.RoleDefinitions.GetByType(SPRoleType.Administrator); //or whichever
SPRoleType you choose
//Get SPListItem
SPList List = Web.Lists["<list name>"]; //e.g., "Announcements"
SPListItem ListItem = List.Items[1];
//Create new Role Assignment
//Add Role Definition to Role Assignment's Role Definition Bindings
SPRoleAssignment RoleAssignment = new SPRoleAssignment("<login name>", //e.g., "MYDOMAIN\UserA"
"<email address>", //e.g., "usera@example.com"
"<display name>", //e.g., "User A"
"<notes>"); //e.g., "Here are some notes."
RoleAssignment.RoleDefinitionBindings.Add(RoleDefinition);
//Check for permission inheritance, and break if necessary
if(!ListItem.HasUniqueRoleAssignments)
{
ListItem.BreakRoleInheritance(true); //pass true to copy role
assignments from parent, false to start from scratch
}
//Add Role Assignment to SPListItem's Role Assignment Collection
ListItem.RoleAssignments.Add(RoleAssignment);
ListItem.Update();
}
}
}
I hope i can used on my project on the client right now, because i need to setting the security and seting worflow on the that list.