Tuesday, September 29, 2009

How to Cutomise SharePoint TaskList

Hello friends,
now i m gone discuss with you on well know topic of SharePoint Site List Item Edit Mode. Whenever user of site edit a listItem. As soon as he edit the item ans mark it as "Completed".
We need to make that item as read only. So further in future nobody can re-edit it. For that i have created a small Costume Activity Using VS.Net 2008. Which further install in SPD. So we can create a workflow to use that.
We are working on List so we need a object of task list, then listItem too. So we know some basic about SPD. Normally like in Workflow we don't have the object like "WorkFlowProperties" in Workflows created in in .net. we have another object for SPD, named as "DependencyProperty ". In details u can understand from code only.
Here is code snapshot in costume activity.


public static DependencyProperty __ContextProperty = DependencyProperty.Register("__Context", typeof(WorkflowContext), typeof(ListItemEditModeDisable));
public static DependencyProperty ItemURLProperty = DependencyProperty.Register("ItemURL", typeof(string), typeof(ListItemEditModeDisable));
---------
SPListItem item = __Context.Web.GetListItem(ItemURL);
string username = item["Assigned To"].ToString();
int no = username.LastIndexOf('#');
no++;
username = username.Substring(no);
SPUser user = __Context.Web.AllUsers[username];

SPGroup newGroup = user.Groups[0];
SPRoleAssignment roleass = new SPRoleAssignment((SPPrincipal)newGroup);
SPRoleDefinition roldef = __Context.Web.RoleDefinitions.GetByType(SPRoleType.Reader);

__Context.Web.AllowUnsafeUpdates = true;

if (item.HasPublishedVersion)
{
item.BreakRoleInheritance(false);
__Context.Web.AllowUnsafeUpdates = true;

}

roleass.RoleDefinitionBindings.Add(roldef);
item.RoleAssignments.Add(roleass);

After You created this costume activity. U need to deploy this in SPD. Just create a workflow for all lists on itemEdited Event. And you have done.
Thanks

No comments:

Post a Comment