Monday, April 27, 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.....

4 comments:

  1. did u check this

    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.workflowactions.createtask.specialpermissions.aspx


    Remarks
    Specifying per-item access control list (ACL) rights is resource intensive and may negatively impact workflow performance.

    ReplyDelete
  2. To assign permissions to a sharepoint group, use the SPGroup.Name in place of the user's loginName.

    ReplyDelete
  3. hi i have a requirement, in that i should filter the items of a list based on creator and other requirement is to filter the items based on specific group.

    ReplyDelete
  4. i have a requirement such that items of a list should be filtered based on creator of the list.and another requirement is to filter the items of a list based on sharePoint group

    ReplyDelete