Scenario 1: A workflow customized using SharePoint designer or a workflow provided by a template
You can use the eventhandler Extension Method to add the permission control statement to the itemadded eventhandler task list of the new task.
Only assign the permission of the current item to the task assign to object, or assign the read-only permission to other users.
Code
Private Void Setownerasonlyeditor (splistitem item)
{
Spweb myweb1 = Item. Web;
/**/ /**/
/**/ ////Get the task owner from the item. 'assigned to 'is a built-in property, so it shoshould be in all lists.
String Authorvalue = Item [ " Assigned " ]. Tostring ();
Spfielduservalue authoruservalue = New Spfielduservalue (myweb1, authorvalue );
Spuser authoruser = Authoruservalue. user;
// Break the security of the item from the list, but keep the Permissions
Item. breakroleinheritance ( True );
Sproleassignment roleassignment = New Sproleassignment (authoruser. loginname, authoruser. Email, authoruser. Name, authoruser. Name );
Roleassignment. roledefinitionbindings. Add (myweb1.roledefinitions [ " Contribute " ]);
Foreach (Sproleassignment roleassignment In Item. roleassignments)
{
// Delete the existing Permissions
Roleassignment. roledefinitionbindings. removeall ();
// Add the reader permission
// Change the permissions of everyone with access to this item so they are readers only
Roleassignment. roledefinitionbindings. Add (myweb1.roledefinitions [ " Read " ]);
Roleassignment. Update ();
// Item. Update ();
}
Item. roleassignments. Add (roleassignment );
Item. Update ();
}
Source code
Scenario 2: Custom workflows using vs2005 Encoding
Assign a value to the specialpermission attribute in createtask, and write the user to which the permission is to be granted.
Note the following two points:
1. To use specialpermission, you must first define a global public variable.
Public hybriddictionary task1permission = new hybriddictionary ();
2To assign this new variable to the specialpermission attribute of createtask, click the blue exclamation point next to the specialpermission attribute. This will bring up the property binding window to bind this variable.
After the above two points are completed, you can implement permission control.
KeyCodeYes:
Task1permission. Add (taskprops. assignedto,Sproletype. Contributor );