Can any one let me know how to add a new task for each user from people picker.

For example In my people picker i have 3 users (john,kevin,Tom).I want to create 3 separate tasks in task list for these users. I want it through Code.Can any one help me on the same.

Thanks, Sandy

  • 1
    Are you creating the Tasks using Workflow.? – Karthik Jaganathan Sep 13 '13 at 10:26

First get selected user's from people picker field,

//Get the collection of users from people editor  

SPFieldUserValueCollection srvcRepCol = new SPFieldUserValueCollection(); 

for (int index = 0; index <= this.peopleEdControl.ResolvedEntities.Count - 1; ++index)
      PickerEntity objEntity = (PickerEntity)this.peopleEdControl.ResolvedEntities[index];
      srvcRepCol.Add(new SPFieldUserValue(srvcWeb, Convert.ToInt32(objEntity.EntityData["SPUserID"]), objEntity.Key));

Code Reference 1

Now get user's using this code and create a task for them

foreach(SPFieldUserValue uValue in srvcRepCol)
   using(SPWeb web = new SPSite("url").OpenWeb())
         SPUser user = web.SiteUsers[uValue.User.LoginName];
         SPList oTaskList = web.Lists[GUIDid];
         SPListItem oTaskItem = oTaskList.Items.Add();
         oTaskItem[SPBuiltInFieldId.Title] = "";
         oTaskItem[SPBuiltInFieldId.Priority] = "(2) Normal";
         oTaskItem[SPBuiltInFieldId.AssignedTo] = user;
         oTaskItem[SPBuiltInFieldId.Description] = "";


Some of Code is hand written so watch out for typo mistakes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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