Wednesday, 21 September 2011

CreateTask.SpecialPermissions in Workflows

I am sure that at some point you have came with this problem; You crate tasks in your task list and another user has deleted them, because he/she thought they were rubbish.

Well, there is a way to tell Sharepoint 2010 to display the tasks for a particular user and prevent this to happen.

You will be using CreateTask.SpecialPermissions. This is an example of how to use it.

//## It creates a task.
CreateTask _ctTask = new CreateTask();
//## We assign the properties for the task.
_ctTask.TaskProperties.AssignedTo = @"DOMAIN/USER";
_ctTask.TaskProperties.Title = "Task title";
_ctTask.TaskProperties.Description = "Task description";
_ctTask.TaskProperties.DueDate = DateTime.Now.AddDays(3);
_ctTask.TaskProperties.EmailBody ="Email body";
_ctTask.TaskProperties.SendEmailNotification = true;
//## This part will give permisions to teh user with the admin role
System.Collections.Specialized.HybridDictionary _hPermissions = new System.Collections.Specialized.HybridDictionary();            
_hPermissions.Add(_ctTask.TaskProperties.AssignedTo, SPRoleType.Administrator);
//## SpecialPermissions assigned!
_ctTask.SpecialPermissions = _hPermissions;

Conclusion: As you can see SpecialPermissions will be a really important tool to consider when you build your workflows.

No comments: