Thursday, 14 July 2011

How to determine if your 'Assigned To' field contains user(s) or group(s)

public override void ItemAdded(SPItemEventProperties properties)
{
 // Check that the item has been assigned to someone and that the ListItem isn't an empty one.
 if (properties.AfterProperties["AssignedTo"] != null && properties.ListItem.Name != null)
 {
  this.EventFiringEnabled = false;

  SPFieldUserValue field = new SPFieldUserValue(properties.Web, properties.AfterProperties["AssignedTo"].ToString());

  // Test for a user or group value (null indicates a group)
  if (field.User != null)
  {
   //user  
  }
  else
  {
   //group
  }
  this.EventFiringEnabled = true;
 }
}

No comments:

Post a Comment

Comments are moderated, so you'll have to wait a little bit before they appear!