Update SharePoint multiple user field

Sample code:

item["ParticipantsPicker"]=BuildMultiSPUserValue(new string[]{"user1","user2"},web);

 public static SPFieldUserValueCollection BuildMultiSPUserValue(string[] userValues,SPWeb web)
        {
            SPFieldUserValueCollection userCollection = new SPFieldUserValueCollection();

            foreach (string  item in userValues)
            {
                SPFieldUserValue userValue = ConvertLoginName(item, web);
                userCollection.Add(userValue);
            }

            return userCollection;
        }

        private static SPFieldUserValue ConvertLoginName(string userID,SPWeb web)
        {
            SPUser user = web.EnsureUser(userID);
            SPFieldUserValue userValue = new SPFieldUserValue(web, user.ID, user.LoginName);
            return userValue;
        }

posted @ 2012-05-04 10:20  大刀客  阅读(216)  评论(0编辑  收藏  举报