Sunday, 26 April 2009

How to give specific permissions to a SharePoint list item through C# to a user

SharePoint 2007 allows item level permissions. The is the big change in security trimming from SharePoint 2003. It's really very good and useful in many scenarios like when an item is belongs to others or task assigned to some other person then users can't see other's tasks or they can't edit other's tasks etc.. item level permissions are really good and useful.

Here is a small code, to set specific permissions to a user for a list item.
The below is the exaple from my SharePoint custom workflow to customize the task list.
System.Collections.Specialized.HybridDictionary taskPermissions = new System.Collections.Specialized.HybridDictionary();
taskPermissions[workflowProperties.Originator] = SPRoleType.Administrator;
taskPermissions[taskApprover] = SPRoleType.Administrator;
taskitem.SpecialPermissions = taskPermissions;

taskitem is the task list item. Hope this helps.....

No comments:

Post a Comment