Tags

,

The code below is to get SPUser from a multiple user item column

string strURL = "http://teams/finance/Lists/Product Cost Plant Email List/";
            using (SPSite oSPSite = new SPSite(strURL))
            {
                using (SPWeb oSPWeb = oSPSite.OpenWeb())
                {
                    
                    SPList list = oSPWeb.GetList(strURL);
                    SPListItemCollection items = list.Items;
                    foreach (SPListItem oListItem in items)
                    {
                        if (oListItem["Title"].ToString() == "Test")
                        {
                            String usersString = oListItem["Audience Group"].ToString();
                            SPFieldUserValueCollection userValueColl = new SPFieldUserValueCollection(oSPWeb, usersString);

                            foreach (SPFieldUserValue userValue in userValueColl)
                            {
                                SPUser siteUser = userValue.User;
                                Console.WriteLine("User found: {0}", siteUser.Name);
                            }
                            break;
                        }
                    }
                }
Advertisements