Here is a piece of code (a function) to set Item Level Permission. You can use it as a Web Method in a custom Web Service. This method can be used from Applications outside of SharePoint, provided the user using this application has sufficient privilege to update lists/libraries etc.
public string ItemPermission(string SitePath)
{
string ReturnVal = "";
try
{
SPSite WebApp = new SPSite(SitePath);
SPWeb Site = WebApp.OpenWeb();
SPList list = Site.Lists["TestDocLib"];
SPListItem item = list.Items[0];
SPRoleDefinition RoleDefinition = Site.RoleDefinitions.GetByType(SPRoleType.Contributor);
SPRoleAssignment RoleAssignment = new SPRoleAssignment("<domain>\\<user>", "email", "name", "notes");
RoleAssignment.RoleDefinitionBindings.Add(RoleDefinition);
if(!item.HasUniqueRoleAssignments)
{
item.BreakRoleInheritance(true);
}
item.RoleAssignments.Add(RoleAssignment);
item.Update();
}
catch (Exception ex)
{
ReturnVal += "Permission not set, reason: " + ex.Message;
}
return ReturnVal;
}
Read the complete post at http://blogs.msdn.com/pranab/archive/2007/07/04/how-to-set-item-level-permission-for-moss-wss-list-document-library-programmatically.aspx
Posted
07-03-2007 6:31 PM
by
Pranab Paul's Blog - SharePoint 2007 (MOSS/WSS 3.0) Development Tips