How to get Users Id from a UserMulti Field

If you try to get the ToString() value of a type of UserMulti field you'll get something like
"1;#Username" and for multi-user fields "1;#User1;#15;#UserX". 


It is not necessary that you create a method that parses this string to get the users ID. You can do it like that :


            SPListItem currentListItem = properties.ListItem;
            Guid guid= new Guid("A1075591-DBC7-4b9d-99F4-E03061F7716E");
            SPFieldUserValueCollection values = (SPFieldUserValueCollection)currentListItem[guid];

            foreach (SPFieldUserValue value in values)
            {

                int valueID = value.LookupId;
                string valueTitle = value.LookupValue;

            }


If you have a field of type Lookup and accepting multiple values you can use SPFieldLookupValueCollection.

Enregistrer un commentaire