Hello,
Recently I have create a timer job to alert users to have task on a SharePoint list.
On my list I have on column "Assigned To" and it can contains user or group.
This code test field value to determine if it an "SPUser" or "SPGroup" object and retrieve all assigned users :
-
- SPFieldUser userField = (SPFieldUser)item.Fields.GetField("AssignedTo");
- SPFieldUserValue userFieldValue = (SPFieldUserValue)userField.GetFieldValue(item["AssignedTo"].ToString());
-
- var users = new List<SPUser>();
-
- if (userFieldValue.User != null)
- {
- users.Add(userFieldValue.User);
- }
- else
- {
-
- SPGroup group = web.SiteGroups.GetByID(userFieldValue.LookupId);
- foreach (SPUser user in group.Users)
- {
- users.Add(user);
- }
- }
- foreach(var user in users)
- {
-
- }
If you have any questions you can use comments section ;)