Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am new to SharePoint, sorry if answer to my question is obvious.

I want to forbid deleting some tasks for users. I can use event receiver for my purpose:

public override void ItemDeleting(SPItemEventProperties properties)
{  
    if (...) 
    {
        properties.ErrorMessage = "The task can not be deleted";
        properties.Cancel = true;
    }
} 

But I can't pass data for checking if I can delete the task. I've tryed to use

properties.ListItem.Properties["ForbidDeleting"].ToString().Equals("true")

in the receiver's condition but is there any posibility to set such property in the CreateTask invoking method? I've tryed using Extended properties for it, but this approach doesn't work.

 ....
 task.ExtendedProperties["ForbidDeleting"] = "true"

I can create my class for keeping task Guids and it ForbidDeleting property, but I think it is not a solution but workaround.

Could you help me please? How can I set some task properties (in the CreateTask invoking method) and get it in the event receiver. Is there any built in way to do it?

Thank you in advance.

PS: Sorry for my writing. English is not my native language.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

How do you retrieve Extended Properties? I used this code in my castom form in the past. I think it should work in event receiver.

Hashtable extendedProperties = SPWorkflowTask.GetExtendedPropertiesAsHashtable(taskItem);
var value = extendedProperties[key].ToString();
share|improve this answer
    
Thanks a lot, it seems like this approach works! –  MikhailSP Mar 23 '12 at 15:03
    
Yes. It's really works! –  MikhailSP Mar 26 '12 at 6:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.